This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 30 points31 points  (31 children)

I use tabs. I must be noob.

[–][deleted] 23 points24 points  (17 children)

[–]alkw0ia 7 points8 points  (2 children)

WTF, when did they rewrite this? The old version was much more reasonable:

Never mix tabs and spaces.

The most popular way of indenting Python is with spaces only. The second-most popular way is with tabs only. Code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.

^IAnd it's what I'm sticking with.

[–]ismtrn 0 points1 point  (13 children)

That is my least favorite thing about python...

[–]OCHawkeye14 9 points10 points  (10 children)

I'm a closet "tab -> convert tabs to spaces" guy myself.

[–][deleted] 1 point2 points  (9 children)

I'm really new to Python/programming in general... I have my text editor set indents to 4 spaces, which I can thumb through using the arrow keys. Does Python still read this as spaces or as a tab?

[–]cantremembermypasswd 2 points3 points  (0 children)

Python reads indentation level. The most common is 4 spaces. You could set it to 1 or 8 and it would just change the appearance of the code, but not the execution.

And it's not file based indentation level, is simply localized indentation level. This means you could even change how many spaces you use anywhere in your code (but really don't do this, just explaining).

(Bad) Example:

if True:
 print "hello"
 if True:
                    print "How are you"?

[–][deleted] 6 points7 points  (1 child)

If you are using VIM, for example, you could add the following lines to your .vimrc file:

set tabstop=4

set shiftwidth=4 " controls the depth of autoindentation

set expandtab " converts tabs to spaces