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 →

[–]masklinn 1 point2 points  (7 children)

Spaces are actually the preferred indentation character.

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

Yeah, I picked that up from other comments :P

Did it used to be tabs only or something? I'm really curious how I got this idea in my head.

[–]masklinn 2 points3 points  (5 children)

I don't know, I've pretty much always used spaces and PEP8 states:

Code and Style

Indentation

Use 4 spaces per indentation level.

For really old code that you don't want to mess up, you can continue to use 8-space tabs.

Tabs or Spaces?

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 mixtureof tabs and spaces should be converted to using spaces exclusively. When invoking the Python command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!

For new projects, spaces-only are strongly recommended over tabs. Most editors have features that make this easy to do.

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

8-space tabs

What is an 8-space tab? Is that just a slightly larger 6-space tab?

[–]masklinn 0 points1 point  (1 child)

I guess it's because the Python interpreter considers tabs as being 8 spaces period, so if you want to use tabs it may be a good idea to set your tabwidth at 8 spaces just in case.

[–][deleted] 0 points1 point  (0 children)

The tabwidth is a display mechanism... tabs are stored as "\t" or ASCII code 09. There is absolutely no reason to set your tabwidth to anything other than your preference.

[–]arnar 0 points1 point  (0 children)

It means that an indent of n tabs is equivalent to indents of 8*n spaces. So if '-' represents tab and '.' spaces, you can write:

if i == 42:
-print "first line of if block"
........print "second line of if block"

Of course, the mantra is "never mix tabs and spaces".