<p>I want to start using Python for small projects but the fact that a misplaced tab or indent can throw a compile error is really getting on my nerves. Is there some type of setting to turn this off?</p>

<p>I'm currently using NotePad++. Is there maybe an IDE that would take care of the tabs and indenting?</p>

[{'answer_id': 63094, 'author': 'Asaf Bartov', 'author_id': 7483, 'author_profile': 'https://Stackoverflow.com/users/7483', 'pm_score': 5, 'selected': False, 'text': '<p>No.  Indentation-as-grammar is an integral part of the Python language, for better and worse.</p>\n'}, {'answer_id': 63095, 'author': 'Thomas Owens', 'author_id': 572, 'author_profile': 'https://Stackoverflow.com/users/572', 'pm_score': 2, 'selected': False, 'text': '<p>I do not believe so, as Python is a whitespace-delimited language. Perhaps a text editor or IDE with auto-indentation would be of help. What are you currently using?</p>\n'}, {'answer_id': 63111, 'author': 'tzot', 'author_id': 6899, 'author_profile': 'https://Stackoverflow.com/users/6899', 'pm_score': 2, 'selected': False, 'text': "<p>No, there isn't. Indentation is syntax for Python. You can:</p>\n\n<ol>\n<li>Use tabnanny.py to check your code</li>\n<li>Use a syntax-aware editor that highlights such mistakes (vi does that, emacs I bet it does, and then, most IDEs do too)</li>\n<li>(far-fetched) write a preprocessor of your own to convert braces (or whatever block delimiters you love) into indentation</li>\n</ol>\n"}, {'answer_id': 63119, 'author': 'Mark Biek', 'author_id': 305, 'author_profile': 'https://Stackoverflow.com/users/305', 'pm_score': 3, 'selected': False, 'text': '<p>All of the whitespace issues I had when I was starting Python were the result mixing tabs and spaces.  Once I configured everything to just use one or the other, I stopped having problems.</p>\n\n<p>In my case I configured UltraEdit &amp; vim to use spaces in place of tabs.</p>\n'}, {'answer_id': 63122, 'author': 'Chris Conway', 'author_id': 1412, 'author_profile': 'https://Stackoverflow.com/users/1412', 'pm_score': 2, 'selected': False, 'text': '<p>You should disable tab characters in your editor when you\'re working with Python (always, actually, IMHO, but especially when you\'re working with Python). Look for an option like "Use spaces for tabs": any decent editor should have one.</p>\n'}, {'answer_id': 63124, 'author': 'Justin Standard', 'author_id': 92, 'author_profile': 'https://Stackoverflow.com/users/92', 'pm_score': 2, 'selected': False, 'text': '<p>Not really.  There are a few ways to modify whitespace rules for a given line of code, but you will still need indent levels to determine scope.</p>\n\n<p>You can terminate statements with <code>;</code> and then begin a new statement on the same line. (Which people often do when <a href="http://codegolf.com/" rel="nofollow noreferrer">golfing.)</a></p>\n\n<p>If you want to break up a single line into multiple lines you can finish a line with the <code>\\</code> character which means the current line effectively continues from the first non-whitespace character of the next line.  This visually <em>appears</em> violate the usual whitespace rules but is legal.</p>\n\n<p>My advice: don\'t use tabs if you are having tab/space confusion.  Use spaces, and choose either 2 or 3 spaces as your indent level.  </p>\n\n<p>A good editor will make it so you don\'t have to worry about this. (python-mode for <a href="http://www.gnu.org/software/emacs/" rel="nofollow noreferrer">emacs,</a> for example, you can just use the tab key and it will keep you honest).</p>\n'}, {'answer_id': 63196, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>It\'s possible to write a pre-processor which takes randomly-indented code with pseudo-python keywords like "endif" and "endwhile" and properly indents things. I had to do this when using python as an "ASP-like" language, because the whole notion of "indentation" gets a bit fuzzy in such an environment.</p>\n\n<p>Of course, even with such a thing you really ought to indent sanely, at which point the conveter becomes superfluous.</p>\n'}, {'answer_id': 63216, 'author': 'Bryan Oakley', 'author_id': 7432, 'author_profile': 'https://Stackoverflow.com/users/7432', 'pm_score': 2, 'selected': False, 'text': "<p>I agree with justin and others -- pick a good editor and use spaces rather than tabs for indentation and the whitespace thing becomes a non-issue.  I only recently started using Python, and while I thought the whitespace issue would be a real annoyance it turns out to not be the case. For the record I'm using emacs though I'm sure there are other editors out there that do an equally fine job.</p>\n\n<p>If you're really dead-set against it, you can always pass your scripts through a pre-processor but that's a bad idea on many levels. If you're going to learn a language, embrace the features of that language rather than try to work around them. Otherwise, what's the point of learning a new language?</p>\n"}, {'answer_id': 63289, 'author': 'indentation', 'author_id': 7706, 'author_profile': 'https://Stackoverflow.com/users/7706', 'pm_score': 2, 'selected': False, 'text': "<p>Getting your indentation to work correctly is going to be important in any language you use. </p>\n\n<p>Even though it won't affect the execution of the program in most other languages, incorrect indentation can be very confusing for anyone trying to read your program, so you need to invest the time in figuring out how to configure your editor to align things correctly.</p>\n\n<p>Python is pretty liberal in how it lets you indent. You can pick between tabs and spaces (but you really should use spaces) and can pick how many spaces. The only thing it requires is that you are consistent which ultimately is important no matter what language you use.</p>\n"}, {'answer_id': 63357, 'author': 'Raz', 'author_id': 5661, 'author_profile': 'https://Stackoverflow.com/users/5661', 'pm_score': 3, 'selected': True, 'text': '<blockquote>\n  <p>I\'m currently using NotePad++. Is\n  there maybe an IDE that would take\n  care of the tabs and indenting?</p>\n</blockquote>\n\n<p>I liked <a href="http://pydev.sourceforge.net/" rel="nofollow noreferrer">pydev</a> extensions of eclipse for that.</p>\n'}, {'answer_id': 63403, 'author': 'Arne Babenhauserheide', 'author_id': 7666, 'author_profile': 'https://Stackoverflow.com/users/7666', 'pm_score': 2, 'selected': False, 'text': '<p>Tabs and spaces confusion can be fixed by setting your editor to use spaces instead of tabs. </p>\n\n<p>To make whitespace completely intuitive, you can use a stronger code editor or an IDE (though you don\'t need a full-blown IDE if all you need is proper automatic code indenting). </p>\n\n<p>A list of editors can be found in the Python wiki, though that one is a bit too exhausting: \n- <a href="http://wiki.python.org/moin/PythonEditors" rel="nofollow noreferrer">http://wiki.python.org/moin/PythonEditors</a></p>\n\n<p>There\'s already a question in here which tries to slim that down a bit: </p>\n\n<ul>\n<li><a href="https://stackoverflow.com/questions/60784/poll-which-python-ideeditor-is-the-best">https://stackoverflow.com/questions/60784/poll-which-python-ideeditor-is-the-best</a></li>\n</ul>\n\n<p>Maybe you should add a more specific question on that: "Which Python editor or IDE do you prefer on Windows - and why?"</p>\n'}, {'answer_id': 63450, 'author': 'metadave', 'author_id': 7237, 'author_profile': 'https://Stackoverflow.com/users/7237', 'pm_score': 1, 'selected': False, 'text': "<p>I was a bit reluctant to learn Python because of tabbing. However, I almost didn't notice it when I used Vim.</p>\n"}, {'answer_id': 63819, 'author': 'Andy Baker', 'author_id': 8140, 'author_profile': 'https://Stackoverflow.com/users/8140', 'pm_score': 3, 'selected': False, 'text': "<p>I find it hard to understand when people flag this as a problem with Python. I took to it immediately and actually find it's one of my favourite 'features' of the language :)</p>\n\n<p>In other languages I have two jobs:\n1. Fix the braces so the computer can parse my code\n2. Fix the indentation so I can parse my code.</p>\n\n<p>So in Python I have half as much to worry about ;-)</p>\n\n<p>(nb the only time I ever have problem with indendation is when Python code is in a blog and a forum that messes with the white-space but this is happening less and less as the apps get smarter)</p>\n"}, {'answer_id': 64186, 'author': 'Eli Bendersky', 'author_id': 8206, 'author_profile': 'https://Stackoverflow.com/users/8206', 'pm_score': 0, 'selected': False, 'text': '<p>Many Python IDEs and generally-capable text/source editors can handle the whitespace for you.</p>\n\n<p>However, it is best to just "let go" and enjoy the whitespace rules of Python. With some practice, they won\'t get into your way at all, and you will find they have many merits, the most important of which are:</p>\n\n<ol>\n<li>Because of the forced whitespace, Python code is simpler to understand. You will find that as you read code written by others, it is easier to grok than code in, say, Perl or PHP.</li>\n<li>Whitespace saves you quite a few keystrokes of control characters like { and }, which litter code written in C-like languages. Less {s and }s means, among other things, less RSI and wrist pain. This is not a matter to take lightly.</li>\n</ol>\n'}, {'answer_id': 64899, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>In Python, indentation is a semantic element as well as providing visual grouping for readability.</p>\n\n<p>Both space and tab can indicate indentation. This is unfortunate, because:</p>\n\n<ul>\n<li><p>The interpretation(s) of a tab varies\namong editors and IDEs and is often\nconfigurable (and often configured).</p></li>\n<li><p>OTOH, some editors are not\nconfigurable but apply their own\nrules for indentation.</p></li>\n<li><p>Different sequences of\nspaces and tabs may be visually\nindistinguishable.</p></li>\n<li><p>Cut and pastes can alter whitespace.</p></li>\n</ul>\n\n<p>So, unless you know that a given piece of code will only be modified by yourself with a single tool and an unvarying config, you must avoid tabs for indentation (configure your IDE) and make sure that you are warned if they are introduced (search for tabs in leading whitespace).</p>\n\n<p>And you can still expect to be bitten now and then, as long as arbitrary semantics are applied to control characters.</p>\n'}, {'answer_id': 68052, 'author': 'Ryan', 'author_id': 8819, 'author_profile': 'https://Stackoverflow.com/users/8819', 'pm_score': 1, 'selected': False, 'text': "<p>If you don't want to use an IDE/text editor with automatic indenting, you can use the pindent.py script that comes in the Tools\\Scripts directory. It's a preprocessor that can convert code like:</p>\n\n<pre><code>def foobar(a, b):\nif a == b:\na = a+1\nelif a &lt; b:\nb = b-1\nif b &gt; a: a = a-1\nend if\nelse:\nprint 'oops!'\nend if\nend def foobar\n</code></pre>\n\n<p>into:</p>\n\n<pre><code>def foobar(a, b):\n   if a == b:\n       a = a+1\n   elif a &lt; b:\n       b = b-1\n       if b &gt; a: a = a-1\n       # end if\n   else:\n       print 'oops!'\n   # end if\n# end def foobar\n</code></pre>\n\n<p>Which is valid python.</p>\n"}, {'answer_id': 68061, 'author': 'gnkdl_gansklgna', 'author_id': 10470, 'author_profile': 'https://Stackoverflow.com/users/10470', 'pm_score': 3, 'selected': False, 'text': '<p>Emacs! Seriously, its use of "tab is a <em>command</em>, not a <em>character</em>", is absolutely perfect for python development.</p>\n'}, {'answer_id': 68702, 'author': 'Chris Calloway', 'author_id': 10769, 'author_profile': 'https://Stackoverflow.com/users/10769', 'pm_score': 6, 'selected': False, 'text': '<p>The answer is no.</p>\n<p>At least, not until something like the following is implemented:</p>\n<pre><code>from __future__ import braces\n</code></pre>\n'}, {'answer_id': 69064, 'author': 'Curro', 'author_id': 10688, 'author_profile': 'https://Stackoverflow.com/users/10688', 'pm_score': 0, 'selected': False, 'text': '<p>Check the options of your editor or find an editor/IDE that allows you to convert TABs to spaces. I usually set the options of my editor to substitute the TAB character with 4 spaces, and I never run into any problems.</p>\n'}, {'answer_id': 118216, 'author': 'Dan Lenski', 'author_id': 20789, 'author_profile': 'https://Stackoverflow.com/users/20789', 'pm_score': 1, 'selected': False, 'text': '<p>Nope, there\'s no way around it, and it\'s by design:</p>\n\n<pre><code>&gt;&gt;&gt; from __future__ import braces\n  File "&lt;stdin&gt;", line 1\nSyntaxError: not a chance\n</code></pre>\n\n<p>Most Python programmers simply don\'t use tabs, but use spaces to indent instead, that way there\'s no editor-to-editor inconsistency.</p>\n'}, {'answer_id': 1515244, 'author': 'Gzorg', 'author_id': 183258, 'author_profile': 'https://Stackoverflow.com/users/183258', 'pm_score': 0, 'selected': False, 'text': '<p>Yes, there is a way. I hate these "no way" answers, there is no way until you discover one.</p>\n\n<p>And in that case, whatever it is worth, there is one.</p>\n\n<p>I read once about a guy who designed a way to code so that a simple script could re-indent the code properly. I didn\'t managed to find any links today, though, but I swear I read it.</p>\n\n<p>The main tricks are to <em>always</em> use <code>return</code> at the end of a function, <em>always</em> use <code>pass</code> at the end of an <code>if</code> or at the end of a class definition, and always use <code>continue</code> at the end of a <code>while</code>. Of course, any other <em>no-effect</em> instruction would fit the purpose.</p>\n\n<p>Then, a simple <em>awk</em> script can take your code and detect the end of block by reading pass/continue/return instructions, and the start of code with if/def/while/... instructions.</p>\n\n<p>Of course, because you\'ll develop your indenting script, you\'ll see that you don\'t have to use continue after a return inside the if, because the return will trigger the indent-back mechanism. The same applies for other situations. Just get use to it.</p>\n\n<p>If you are diligent, you\'ll be able to cut/paste and add/remove <code>if</code> and correct the indentations automagically. And incidentally, pasting code from the web will require you to understand a bit of it so that you can adapt it to that "non-classical" setting.</p>\n'}, {'answer_id': 1538995, 'author': 'epic_fil', 'author_id': 185875, 'author_profile': 'https://Stackoverflow.com/users/185875', 'pm_score': 1, 'selected': False, 'text': "<p>I'm surprised no one has mentioned IDLE as a good default python editor.  Nice syntax colors, handles indents, has intellisense, easy to adjust fonts, and it comes with the default download of python.  Heck, I write mostly IronPython, but it's so nice &amp; easy to edit in IDLE and run ipy from a command prompt.</p>\n\n<p>Oh, and what is the big deal about whitespace?  Most easy to read C or C# is well indented, too, python just enforces a really simple formatting rule.</p>\n"}]
['https://Stackoverflow.com/questions/63086', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1231/']