March 26th, 2005, 02:07 PM
Beginner question about indents
I like Python, but find the correct indentations a little cumbersome to count. Is there a visible character that counts as an indentation?
March 26th, 2005, 02:21 PM
I'm a little confused by the question. Do you mean like a character(s) that would do the same thing as pressing tab? That would be '\t'.
Comments on this post
March 26th, 2005, 05:30 PM
i am not sure what he means either. but i think he means an editor showing the tabs...most editors have options to show you the tabs like this: (see attached image) ...althought i don't know if that's what you want.
March 26th, 2005, 06:24 PM
Why are you having to count anything?
March 27th, 2005, 03:53 AM
What editor are you using? If it is something like Notepad then get yourself a proper programmers' editor.
The important thing about Python indentation is that it all the lines in a block line up with each other - the actual number of spaces does not matter. If all the code in a function is on one screen and you are using a fixed width font then you can tell this just by eye. If you are not using a fixed width font then change it - programming in a proportional font is painful. If your functions are bigger than a screen then they are too big anyway, and should be refactored into smaller functions.
A decent editor will help you in many ways, e.g.
* letting you set a tab size and automatically converting tabs into the right number of spaces (4 spaces per tab is the defacto Python standard).
* showing you guide lines when you indent a block
* having a mode where invisible characters become visible (e.g. spaces are converted to a faint dot)
There are lots of free editors that can do some or all of the above - Jedit, SPE, emacs, vim, etc. For a comprehensive roundup of Python-aware editors see here.
Dave - The Developers' Coach
Last edited by DevCoach; March 27th, 2005 at 03:58 AM.
March 27th, 2005, 05:57 AM
If your looking for an alternative way to indent your code then the answer is no. The only characters you can use to indent your Python code (unless you want to run your code though a custom built preprocessor) are tabs and spaces, which won't be visible unless your editor supports this as the guys have said.
Originally Posted by Dietrich
However indentation in the program should be easy to see since your code will line up into blocks.
#This is a code block using indentation.
print "something else"
#This is outside of the code block above.
print "bye ;)"
March 27th, 2005, 06:33 AM
or here for IDEs...
Originally Posted by DevCoach
...and just to underline that there's no absolutely no reason not to use a Python aware editor/IDE, every standard installation of Python comes with IDLE... (I use it - it may not be perfect but it's good enough. ;-)
March 27th, 2005, 09:43 AM
Thanks for all your ideas, sorry about not being clear enough! I am actually using the Crimson Editor, so this example solves what I wanted. I just wanted the tabs/spaces to show up at times, since I gotten errors when the exact amount of spaces didn't match!
Originally Posted by jacktasia
March 27th, 2005, 09:59 AM
Thanks a lot coach! I got the PythonWin editor and like it already. It has a whitespace option with the faint little dots, perfect! Problem solved!
Originally Posted by DevCoach