#1
  1. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    606
    Rep Power
    65

    Smile 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?
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    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

    • jacktasia agrees
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15
    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.
    Attached Images
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    Why are you having to count anything?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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.
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Originally Posted by Dietrich
    I like Python, but find the correct indentations a little cumbersome to count. Is there a visible character that counts as an indentation?
    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.

    However indentation in the program should be easy to see since your code will line up into blocks.

    Code:
    if someExpression:
        #This is a code block using indentation.
        print "something"
        print "something else"
    #This is outside of the code block above.
    print "bye ;)"
    Take care,

    Mark.
    programming language development: www.netytan.com Hula

  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Posts
    78
    Rep Power
    10
    Originally Posted by DevCoach
    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.
    or here for IDEs...

    ...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. ;-)

    --OH.
  14. #8
  15. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    606
    Rep Power
    65

    Red face


    Originally Posted by jacktasia
    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.
    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!
  16. #9
  17. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    606
    Rep Power
    65

    Talking


    Originally Posted by DevCoach
    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
    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!

IMN logo majestic logo threadwatch logo seochat tools logo