I'm coding in Python and I really like Notepad++. However, off late when I use tab to indent, it seems fine in Notepad++, but when I run the program I get an indentation error, and when I check my code in Emacs or something, I find that Notepad++ actually adds more tab spaces than it shows on screen. What is happening?
There is no universal tab size, so I always make sure to replace tabs by spaces (so you know what you see is what you get everywhere else as well)
Go to Settings -> "Preferences..." -> Language Menu/Tab Settings and check 'Replace by space'
I would suggest going to View > Show Symbol > Show Whitespace and Tab to get an better idea of how your indentations look.
PEP 8 tells us to use spaces instead of tabs in Python for cross-editor compatibility and consistency:
http://www.python.org/dev/peps/pep-0008/
Have a look at this answer for how to change tabs to spaces in Notepad++
Convert tabs to spaces in Notepad++
Perhaps that will fix your problem
Tiny update - to get spaces as tabs, you now go to Settings>>Preferences>>Tab Settings and check the "Replace by space" box
I am new to python and started using Notepad++. But I faced the same issue as you... Indentation problems. On my senior's advice, I switched to PyCharm community edition. I pasted the code from Notepad++ to PyCharm and it highlighted the block with indentation problems... The issue was that, some of the lines used spaces and some used tabs. This happened because the code on which I was working was taken from the internet.
Checking for such inconsistencies would solve the problem. Or, there is a better alternative... Switch to PyCharm. It is exclusively built for python coding.. Hope this helps people like me searching for solutions for indentation issues in Notepad++
Use Python Indent Plugin for Notepad++:
I have used both Pycharm & Notepad++, and frankly - even though both are installed on my machine right now I prefer using Notepad++. So, if you want to continue using Notepad++ for Python development you should definitely install the 'Python Indent' Plugin. This plugin will automatically create tabs for you when writing Python code. The only downside to the plugin is you have to remember to Enable it (by going to Plugins --> Python Indent and then clicking 'Enable') when you want to use it.
To install the Python Indent plugin in Notepad++ just go to 'Plugins' --> 'Plugin Manager' and then click on 'Show Plugin Manager'. Then check off 'Python Indent' and click on the 'Install' button.
Additionally, you should Follow Python's Usage Guide:
Tab spacing can differ across programs and, following the recommendations of PEP8 (Python Enhancement Proposals Number 8 - which is Python's Accepted Styling and Usage Guide) you should use the space bar to make your indents. Check out the PEP8 Page about spacing here: https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces
Good luck!
Related
How can I add Indentation lines like what is shown above in Jupyter Lab/Notebook?
I have tried a lot and went into the settings (not much as I am a beginner and I don't know most of the stuff) but in Jupyter I can only get code numbers from the View button but not these beautiful lines which help a lot when doing the indentation.
The default editor used by Jupyter Notebook and JupyterLab (CodeMirror) does not support indentation markers as for today; it is possible to extend it with an add-on but it seems that there isn't one yet (see Indentation Markers with CodeMirror). I imagine that you would need to create a custom overlay mode to make it work, and it might be in scope for jupyterlab-lsp extension if you would like to suggest this via issue on GitHub.
JupyterLab also allows to use a different editor via extension (and there was a proof-of-concept for that) but I don't think that anyone volunteered to maintain any other editor integration recently.
In the near future JupyterLab will likely migrate CodeMirror 6, and depending on availability of such feature in it it will either have a support for it or not. Or maybe someone will contribute a support for it to an extension. It might turn out to be easier to implement in CM6.
When I am writing Python in V.S. Code, I keep getting errors that highlight a good portion of my code base. IntelliCode shows an error message that reads:
"unexpected token '=' Python(parser-16)"
So, it appear to stem specifically from specific lines, and when the lines are copy & pasted they inherit the errors, however; if you type-out the line anew, the error is resolved? It is a perplexing issue.
There are 3 things that could be
The first is simple, restart your editor and see if the issue persists.
The second thing it could be is an old unmaintained extension:
Installing the wrong extensions can cause headaches and hard-to-solve issues. This is why installing extensions because it's fun, and they are free, is a bad idea. You should always have a decent reason for installing an extension, and should always avoid installing an extension under the pretense that you may, one day, need it.
When it comes to an opensource editor like VSCode, extensions are Hit & miss, which is, to say the least. Sometimes you might find a hidden-gem, or something new the surprises you unexpectedly in a good way, but you need to have a reason to be looking for a specific extension because you need to know what your look for, many extensions offer features that VSCode now supports out of the box, some extensions haven't been upgraded for 2-3 years, and are full of deprecated code. There is an example of a repository that was maintained by Microsoft up until 2020. People are still creating issues that reference parser 16 errors, and they only get a response that the repository is no longer maintained, and a suggestion to use a different tool."_
Here's the link to the repository I mentioned above. I don't know what extensions you are using, but if it uses this old language server repo, which is for some reason still active, you will want to swap out that extension for something else, or just toss it all together.
To test if it is an extension perform the simple steps below:
To confirm that it is an extension...
OPEN Your Project inside of V.S. Code
HIT F1 to open up your quick input menu
TYPE: "Reload window with extensions disabled"
SELECT the command from the menu that matches the text you typed in step-3 above ("Reload Window with Extensions Disabled") (or workbench.action.reloadWindowWithExtensionsDisabled)
After the editor reloads check your and see if the issue persists.
The problem should go away, as you shouldn't have syntax highlighting from an extension enabled. You need to accomplish having Syntax Highlighting W/O having the issue though. To do this you're going to temporarily leave all of your extensions disabled, then, if you don't have it, install the extension pack that is called:
Python (that's it, its just called "Python").
If you do have it, then just enable it. The V.S. Code Python Extension adds Microsoft support to V.S. Code for Python. Make sure that the extension ID-Name is ms-python. python, that it was developed by Microsoft, and that you have the latest version.
After you have your project open with all extensions, except for the Microsoft Python extension installed, see if the issue is gone and that your syntax highlighting works.
The third and last thing it could be is the Python Extensions parser is unable to parse your code, which may, or may not be your fault.
If the above did not solve your issue then it's likely that the issue is a problem with your code, which may, or may not, be your fault. Python syntax is funny, as it's far different than other c-style languages, yet it is still very much C-style. In the past, I have seen parser 16 errors caused by F-strings, and R-Strings, because of bugs in the parser. They either had a hard time picking up multiple quotes """ in a row, or they had a hard time, picking up a logic-operator with multiple quotes, the syntax written like the following example would cause an error in specific use cases:
"""!==
You need to go through, make sure it's not a mistake on your end, you can even post your code here, which would help the community to determine if its a bug, especially if you can confirm for us that you have only the python extension active while you are getting the error.
If you determine that your codebase is in working order, and if you are right, it is in working order, then it is likely a bug, but you need to like really, really be sure. Once you are sure, go to the following repository and create an issue.
VSCode-Python Repository (CLICK HERE)
Some characters might not be what they look like on text editor.
For example:
Non-breaking space is different from space even though they look the same.
״ is different from " even though the looks similar on the screen.
’ different from ' even though the looks similar on the screen.
So when copy a code and paste a code from somewhere and you get syntax errors you do not understand such as unexpected token, Try to replace the characters at the relevant locations.
Had similar problem with python code.
In my case restarting VSC solved problem.
Debugging the problem
Turn off extensions
To test if one of your VSCode extensions is causing the error, open the command pallatte(cmd+shift+p or ctrl+shift+p) and select Reload Window with Extensions Disabled to see if the problem still exists without any extensions
Start Extension Bisect
Also, if you go to the vscode extensions marketplace, there is an option called start extension bisect which vscode explains as
Extension Bisect will use binary search to find an extension that causes a problem. During the process the window reloads repeatedly (~7 times). Each time you must confirm if you are still seeing problems.
Advice on Extensions
The Python extension that is developed by microsoft is ms-python.python, this is usually the one you want
Don't install extensions you don't understand, it can cause hard-to-solve problems.
Any time you do install an extension, check to see if you are having any errors or problems.
I've used this guide to set up Xcode to build Python scripts. When I press return, the cursor always goes back to the beginning of the new line, even though automatic indenting based on syntax is turned on in the preferences menu. It's frustrating to have to press the space key eight times to get two blocks in indenting in every time. Is there something I haven't installed correctly? I have Anaconda installed and as my build tool if that helps.
I would suggest running Python on something else imho. Something like PyCharm or IPython. The problem with Xcode is that Python is not one of the native languages for it. So Xcode doesn't know the proper formatting for Pythons syntax.
Not to mention that debugging and other features might not work well on Xcode.
I know Notepad++ supports Python but under the language menu I cannot find it! At "P," it only lists
Pascal, Perl, PHP, Postscript, PowerShell, and strangely, Properties. I am writing some Python scripts and I want the
syntax to be highlighted. How can I activate Python highlighting?
Maybe it's disabled. Check in Preferences | Language Menu/Tab Settings if it's not among the disabled items.
Weird. I have Notepad++ v6.3 on this PC and it is there:
Try to uninstall and reinstall Notepad++. Be sure to get the latest version from SourceForge -
http://sourceforge.net/projects/notepad-plus/
Please make sure it is not disabled. I happens to me too.
To check go to preferences, click on language items in the left and make sure that python is not in disabled languages.
Reboot notepad++ after applying changes.
Try to uninstall and install the new version form Notepad++
On mine, notepad++ v7.5.8, Python is not in the P section but it is in the bottom of languages menu.
This is the default arrangement for my version of notepad++ so all bets are off if you changed it under settings.
Yes, python is at the bottom of language list (not under P item - I believe it was moved out of P after I played with Settings) .
I am turning to Python from .NET world. And Visual Studio was something a great tool i used.
In python world we do have basic IDLE and another one is VIM. I have seen that a lot of developers have configured VIM to a great IDE. Using basic VIM in Windows 7 seems of less use.
So i want to moderate my VIM to a level which has file explorer, syntax highlighting, search, error highlighting etc. So that it gives feel of Visual Studio and more productive.
But all hacks/tips available are for Linux/Ubuntu users mostly, which i may use later but as of now i need to make my VIM in Windows more productive, visual.
Please Suggest some Tips/Hacks/Resources to look around for VIM configuration?
Thanks
This question addresses your low level issue: coding Python with an IDE that is not VS.
There are a few popular blog posts addressing your high level issue: setting up Vim for Python development. They are a quick google away…
I feel the need to point out that Vim is not an IDE. You can customize it a lot and end up with something that looks like an IDE but you won't get an IDE. Only an over-customized text editor.
Anyway, here are a few tips for starting out with Vim:
Do $ vimtutor as many times as needed to feel comfortable with the basics.
Get familiar with Vim's buit-in documentation: the answers to most of your questions are somewhere inside. :help gets you to the front page, :help 'option' shows the documentation for option, :help :command shows the documentation for command… Hit <C-]> on a colored word to jump to its definition.
Don't use Janus or SPF13 or whatever pre-packaged set of plugins. You'll only grow bad habits. Similarly, don't copy other people's vimrc wholesale.
Ctags is an external code indexer that is used by Vim to "jump to definition" with <C-]>. cscope is another option, it's more powerful but also a little more complex. See :help tags.
Related to ctags, TagList and TagBar are two popular plugins used to display more or less the equivalent of the Object Browser in VS.
NERDTree is another popular plugin that mimicks the file tree found in many IDEs/editors. But Vim comes with netrw (:Ex) by default, try it before installing NERDTree.
Read :help motion.txt as soon as possible.
Watch Drew Neil's laser-guided vimcasts.
Don't rush it.
you can use vim plugins on windows, http://www.vim.org/scripts/index.php, typing "vim {your feature here}" into google will come up with lots of results.
popular file explorer is nerdtree,
syntax highlighting can be turned on with
syntax on in your vimrc
searching open file is easy to do using reg exes . Initialize search with /.
Searching directory is easy to do using grep.
I don't develop on windows but i have read that Cygwin might be worth installing for some linux tools if not already installed.
I am in no way an evangelist of any Editor/IDE.
But, if you are a newbie to Python I would suggest trying out Sublime Text 2 http://www.sublimetext.com/ . It is a very light weight yet powerful editor with a great following and it has a free evaluation version with no deadline.
But, if you intend to work using frameworks such as Django/ GAE then I would suggest using PyCharm from JetBrains
http://www.jetbrains.com/pycharm/
Finally, these tools are all just personal choices until you get comfortable with one or two of them.
Thanks,
-Hari
One possible compromise is to use your favorite IDE with a vim emulator plugin. For example, in Eclipse you can use Vrapper, PyCharm has IdeaVim and so forth. Lighttable also has vim key-bindings. The plug-ins (or key-binding options) give you some of the benefits of editing in Vim while still having the powerful debugging / navigation features, etc. of a full-blown IDE. BTW, Vrapper works with PyDev.
Using an emulator in an IDE allows you to gain the "muscle-memory" necessary for effective vim editing, without getting bogged down in "configuration hell" associated with turning an editor into an IDE (which auto-complete plugin do I use?..etc.?). Once you have mastered the vim keystrokes for normal and visual mode, used along with insert mode, you may decide to continue on into pure Vim and face those issues.
I wouldn't recommend to learn VIM in 2012 (despite it being a great editor). If you must, this blog post will get you started.
But VIM isn't an IDE, it's a text editor.
If you really want a powerful IDE, try IntelliJ IDEA or Eclipse. Both have great plugins to turn them into Python IDEs (along with code completion and all the other nice time savers). For Eclipse, try PyDev. For IntelliJ, search for Python in the plugin preferences pages.