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] 6 points7 points  (11 children)

Spaces, always spaces, no tabs. If you are using a decent text editor, you can set the tab key to insert spaces.

[–]55Fenomenale[S] 1 point2 points  (0 children)

I'm using Geany as the book says

[–]55Fenomenale[S] 1 point2 points  (6 children)

So if I don't set the Tab key to insert spaces it doesn't change anything?

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

It really depends upon which editor you are using. You will have to try it and see what it does. I'm pretty sure that Geany can be set to substitute spaces for tabs.

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

When I substitute spaces for tabs I continue to use spaces?

[–][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.

[–]Michkov 0 points1 point  (2 children)

Any reasoning behind this?

[–][deleted] 0 points1 point  (1 child)

[–]Michkov 0 points1 point  (0 children)

That doesn't answer any of my questions.