Misuse of <tab>

Justin Guerin jguerin at cso.atmel.com
Thu Jul 31 19:02:37 CEST 2003

On Wednesday 30 July 2003 10:20 am, Gisle Vanem wrote:
> I'm a .py newbie and fascinated by the simplicity of formatting.
> No need for {} as in Perl etc. But the misuse of <tab> that many
> .py writers do makes it hard to understand how a script operates.
> E.g.
> def main():
>    terminate = 0
>    def foo():
>        line = sys.stdin.readline()
> <tab>  try:
>         bar()
>     except:
>         terminate = 1
> main()
> Now, with an editor with different tab-settings it's difficult to see where
> the try statement belongs. In 'def main()' or in 'def foo()' ?
> I'm confused, please enlighten me.
> --gv

In this case, you can tell by the except clause.  except: can only follow a 
try:, and they must be on the same indent level.  Also, if the try: was in 
'def foo()', 'bar()' would have to have a higher indent level than 'line = 
sys.stdin.readline()'.  (From what I can see, it does, but I'm not sure that 
was intended, as the except came in at a different indent level from either)  
So for this example, the try: belongs in 'def main()'  


More information about the Python-list mailing list