Notepad++ indentation messes up

PythonNotepad++Indentation

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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'

Solution 2 - Python

I would suggest going to View > Show Symbol > Show Whitespace and Tab to get an better idea of how your indentations look.

Solution 3 - Python

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++

https://stackoverflow.com/questions/455037/notepad-tabs-to-spaces

Perhaps that will fix your problem

Solution 4 - Python

Tiny update - to get spaces as tabs, you now go to Settings>>Preferences>>Tab Settings and check the "Replace by space" box

Solution 5 - Python

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++

Solution 6 - Python

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!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questioniman453View Question on Stackoverflow
Solution 1 - PythonikottmanView Answer on Stackoverflow
Solution 2 - PythonAshley GrenonView Answer on Stackoverflow
Solution 3 - PythonNobodyView Answer on Stackoverflow
Solution 4 - PythonNotAnAmbiTurnerView Answer on Stackoverflow
Solution 5 - PythonVikasView Answer on Stackoverflow
Solution 6 - PythonJaxianView Answer on Stackoverflow