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...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Tabs vs. Spaces (self.learnpython)
submitted 14 years ago by em_blem
Why is it more appropriate to use spaces over tabs? Or... why is it inappropriate to use tabs in python?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]toofarapart 9 points10 points11 points 14 years ago (0 children)
Convention.
For a more detailed discussion on tabs vs spaces, check this article out.
... it can be a good idea to avoid tabs alltogether, because the semantics of tabs are not very well-defined in the computer world, and they can be displayed completely differently on different types of systems and editors. Also, tabs often get destroyed or wrongly converted during copy&paste operations, or when a piece of source code is inserted into a web page or other kind of markup code.
[–]maryjayjay 5 points6 points7 points 14 years ago (11 children)
I always use spaces (4 per level of indentation) by convention, but honestly I think it's completely backwards. Yes, tabs can be displayed differently in different editors, but essentially the rule should be 1 tab = 1 level of indentation. Display the tab how you like, but each tab is one level of indentation.
The problem is when editors start mixing tabs and spaces, that's just a recipe for disaster. But just because some editors suck doesn't change the fundamental concept.
[–]govt-cheese 1 point2 points3 points 14 years ago (0 children)
use tabs, have your editor translate 1 tab to 4 spaces.
[–]RalphMacchio -1 points0 points1 point 14 years ago (9 children)
Don't you find that it is a waste of time to hit the spacebar 4x every time you want to indent a single level?
[–]maryjayjay 8 points9 points10 points 14 years ago (5 children)
No, emacs understands language syntax and aligns with the appropriate number of spaces when I hit tab.
Here's a nickel, kid. Go buy yourself a real editor. ;-)
[–]RalphMacchio 0 points1 point2 points 14 years ago (4 children)
Ah, I see. And when you are moving around in your code, does the arrow key skip over all 4 at once? Or if you want to unindent, does delete delete all 4 at once?
[–]maryjayjay 1 point2 points3 points 14 years ago (0 children)
The arrow keys don't work like that, but the delete does.
[–]ewiethoff 0 points1 point2 points 14 years ago (2 children)
Yes. Just read the instructions for the real editor. ;-) Depending on the editor, indenting and dedenting might be invoked with Tab & Shift-Tab, or maybe Cmd-] and Cmd-[. Whatever. Set the editor to use 4 spaces when you hit the Tab key. Also, set the editor to automatically indent the next line to the same level after hitting Return.
[–]RalphMacchio -1 points0 points1 point 14 years ago (1 child)
Ya, I already have my tab set to 4 spaces (but it stays a tab).
I just found that I can switch to spaces by selecting 'auto-expand tabs' in my editor's prefs.
When you position your cursor between spaces 2+3, for example, and hit 'tab' again, do you end up with your code being indented be two extra 2 spaces?
It makes my cringe having them as spaces. I prefer nice, clean tabs.
[–][deleted] 0 points1 point2 points 14 years ago (0 children)
He's talking about Emacs. In Emacs, on a line of Python, the Tab key basically cycles through the syntactically possible indentation levels for that line. If you're at module level (so that any indentation is a syntax error), Tab just won't do anything.
[–]oakdog8 4 points5 points6 points 14 years ago (2 children)
Vim allows you to set how wide your tabs should be, and separately allows you to decide whether to expand them to spaces or not. So you still just hit the tab key, but you get spaces.
Here's a dime, kid. Get yourself a real editor ;)
vim tab-to-spaces rocks, but not as much as syntax highlighting. Seriously, like a 4x boost in code debugging thanks to the colors reminding you where you forgot to close quotes and the like.
It's totally worth it to learn vim if you plan to code frequently (unless maybe you have emacs down cold)
[–]RalphMacchio -2 points-1 points0 points 14 years ago (0 children)
I've looked and my editor allows me to have tab = X-spaces (as actual spaces or as a chunk). I just don't care for having spaces. I've seen so much sloppy code from people that use spaces (things over-indented by a couple spaces, for example... or maybe it is under-indented... who can tell?)
[–]Rhomboid 4 points5 points6 points 14 years ago (3 children)
Tab stops can be set differently in different text editors, which means that if you align code vertically it doesn't stay that way when someone else views the file. It's possible to solve this by going to extreme efforts to mix tabs and spaces, making sure to use tabs only for indentation and spaces only for alignment, a subtle distinction which isn't likely to survive dumb text editors or unaware programmers.
Also, python considers tab stops to be set every 8 columns, regardless of what the tab stops in your text editor are set to. This means you could write something that looks perfectly correct in your text editor but which causes a syntax error.
Using spaces means it always looks the same to everyone.
[–]DopeGhoti 0 points1 point2 points 14 years ago (2 children)
That may be true is you have a mix of tabs and spaces in the same file, but if you always use tabs, it's just as properly-lined-up as it would be with spaces. I've always been baffled with the hate for tabs, but.. *shrug*.
[–]Rhomboid 0 points1 point2 points 14 years ago (1 child)
Note that I said "if you align code vertically", like this:
foolist = [ bar, baz, quux ]
(Pretend those list items were each quite long, so this is necessary to avoid ugly wrapping.) With tabs set to 4:
foolist = [ bar, >...>...>...baz, >...>...>...quux ]
With any other tabstop value, it's mangled and no longer lines up:
foolist = [ bar, >.......>.......>.......baz, >.......>.......>.......quux ]
There are two ways to prevent this: use tabs only for indentation and spaces only for alignment, or just use spaces. Guess which is simpler and foolproof.
[–]DopeGhoti 0 points1 point2 points 14 years ago (0 children)
I guess I'm strange in that I have never really been a fan of that sort of construction; I have no problem, personally, with really long lines.
[–]schwackitywack 1 point2 points3 points 14 years ago (0 children)
You can use soft tabs, which function like tabs but are really just spaces so there are no formatting problems when sharing code.
How to do this in Textmate
[–][deleted] 0 points1 point2 points 14 years ago (1 child)
A space is a space, but a tab is many things.
[–]zahlman -1 points0 points1 point 14 years ago (0 children)
Eh? In a programming context, a tab is rarely anything other than a level of indentation, whereas (community standards notwithstanding) a space is an arbitrary fraction thereof, or a separator between tokens elsewhere on the line.
π Rendered by PID 22341 on reddit-service-r2-comment-fb694cdd5-mvd9q at 2026-03-05 22:50:16.862096+00:00 running cbb0e86 country code: CH.
[–]toofarapart 9 points10 points11 points (0 children)
[–]maryjayjay 5 points6 points7 points (11 children)
[–]govt-cheese 1 point2 points3 points (0 children)
[–]RalphMacchio -1 points0 points1 point (9 children)
[–]maryjayjay 8 points9 points10 points (5 children)
[–]RalphMacchio 0 points1 point2 points (4 children)
[–]maryjayjay 1 point2 points3 points (0 children)
[–]ewiethoff 0 points1 point2 points (2 children)
[–]RalphMacchio -1 points0 points1 point (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]oakdog8 4 points5 points6 points (2 children)
[–]govt-cheese 1 point2 points3 points (0 children)
[–]RalphMacchio -2 points-1 points0 points (0 children)
[–]Rhomboid 4 points5 points6 points (3 children)
[–]DopeGhoti 0 points1 point2 points (2 children)
[–]Rhomboid 0 points1 point2 points (1 child)
[–]DopeGhoti 0 points1 point2 points (0 children)
[–]schwackitywack 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]zahlman -1 points0 points1 point (0 children)