简体   繁体   中英

Indentation when copying from notepad++ into jupyter python notebook

I am working in a jupyter notebook (python 2.7) in the cloud to be able to run tensorflow (which fails to run on my own environment) and trying to copy in an existing script from Notepad++. The script runs fine, and Jupyter automatically converts tabs into arrows (see below). The original scripts run fine - but any additional lines that I add interactively (eg by pressing enter, such as line c per below) do not have the "arrow-like" indentation, and give indentation errors. I looked around for answers, but struggled to find suggestions. I could make all edits in Notepad++, and copy back and forth, but I was wondering if there is a way to either a) copy in text without autoindentation issues or b) be able to add correctly auto-indented lines interactively. 在此输入图像描述

The arrow is a visual symbol to help you see that you have a tab there. You can verify that by looking at it from command line (just do type filename.py if you are in Windows' cmd shell). The autoindent seems to be using spaces instead of tabs. Set your editor to use tabs for autoindent, when possible. Assuming the editor has that option, you should be fine then.

This answer uses Sublime Text 2 (though I imagine editors are similar). Change your settings to indent using spaces (for future code you write). Highlight old code and convert indentation to spaces.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM