Is there a way around coding in Python without the tab, indent & whitespace criteria?

前端 未结 29 1123
小鲜肉
小鲜肉 2020-12-31 14:05

I want to start using Python for small projects but the fact that a misplaced tab or indent can throw a compile error is really getting on my nerves. Is there some type of s

29条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 14:41

    If you don't want to use an IDE/text editor with automatic indenting, you can use the pindent.py script that comes in the Tools\Scripts directory. It's a preprocessor that can convert code like:

    def foobar(a, b):
    if a == b:
    a = a+1
    elif a < b:
    b = b-1
    if b > a: a = a-1
    end if
    else:
    print 'oops!'
    end if
    end def foobar
    

    into:

    def foobar(a, b):
       if a == b:
           a = a+1
       elif a < b:
           b = b-1
           if b > a: a = a-1
           # end if
       else:
           print 'oops!'
       # end if
    # end def foobar
    

    Which is valid python.

提交回复
热议问题