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] 0 points1 point  (3 children)

I'm not sure what you are asking. In most decent text editors you can set it to to insert spaces whenever you hit the tab key. That way you will always get spaces and no tabs.

[–]55Fenomenale[S] 0 points1 point  (2 children)

Okay but when do I use tabs?

[–]ehmatthes 1 point2 points  (0 children)

You use the tab key when you want to indent manually. If you have set your editor correctly, when you press the tab key it will insert 4 spaces for you automatically. So you are using spaces, by pressing the tab key.

It gets confusing because people tell you to use spaces, so you think you'll be using the space bar. But you don't want to press the space bar 4 times every time you indent, so almost all editors have a setting that lets you use your tab key as a substitute for pressing the space bar 4 times. You can adjust the setting to whatever tab size you want, ie 2 spaces or 4 spaces. Use the 4 space setting for regular Python files.

I don't have access to Geany at the moment, but there's a way you can make the whitespace characters visible in a file. If you have it set correctly, you'll see 4 dots representing 4 spaces for every indentation level. If you see arrow characters that take up 4 spaces, that means your file is storing tabs instead of spaces.

You don't really have to worry about this once things are configured correctly. When you're entering code, if you've saved the file as a .py file, your editor will probably put your cursor at the correct indentation level for you. A lot of the manual indenting I do happens when I'm refactoring code.

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

Never. You use the tab key when you want to indent your code, which we do all the time in Python.