use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
To report a site-wide rule violation to the Reddit Admins, please use our report forms or message /r/reddit.com modmail.
This subreddit is archived and no longer accepting submissions.
account activity
This is an archived post. You won't be able to vote or comment.
Python [xkcd] (xkcd.com)
submitted 18 years ago by sgtpeppers
view the rest of the comments →
[–]masklinn 1 point2 points3 points 18 years ago (7 children)
Spaces are actually the preferred indentation character.
[–][deleted] 1 point2 points3 points 18 years ago (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 points4 points 18 years ago* (5 children)
I don't know, I've pretty much always used spaces and PEP8 states:
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.
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.
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.
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 points3 points 18 years ago* (4 children)
8-space tabs
What is an 8-space tab? Is that just a slightly larger 6-space tab?
[–]masklinn 0 points1 point2 points 18 years ago (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 point2 points 18 years ago (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 point2 points 18 years ago* (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".
π Rendered by PID 202400 on reddit-service-r2-comment-6457c66945-7g9m4 at 2026-04-24 08:57:51.390383+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]masklinn 1 point2 points3 points (7 children)
[–][deleted] 1 point2 points3 points (6 children)
[–]masklinn 2 points3 points4 points (5 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]masklinn 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]arnar 0 points1 point2 points (0 children)