namespaces & indentation
Alex Martelli
aleaxit at yahoo.com
Fri Dec 22 17:59:33 EST 2000
More information about the Python-list mailing list
Fri Dec 22 17:59:33 EST 2000
- Previous message (by thread): namespaces & indentation
- Next message (by thread): namespaces & indentation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Chris Schaller" <Chris.Schaller at web.de> wrote in message news:920f54$m2f$1 at news.mch.sbs.de... > Dear Pythoners... > > I always thought that I understood Python's scoping, but then I came across > that code: > > def t(x): > > if x == 1: > > c = 'yeah' > > return c > > If I execute t(1), I'll get 'yeah', but otherwise there'll be an error > message. According to the indentation level c is only valid within the > if-clause, but not on the outside. So I guess, the indentation level only > defines the lines of code that belong to the if-clause, but has nothing to do > with scopes. Right! Only modules, functions, and classes are/have scopes. > That's very confusing, I've already programmed a lot in Python, but only > due to a program error (I forgot to initialize c at the beginning of the > function - a common error) and an unsuccessful test this happened to a program > after months of error-free running. > > Any comments? Your unit tests apparently had scarce coverage if they never followed this particular path. When unit tests have insufficient coverage (a common issue), any bug may lurk in the never-explored paths -- this specific one is nothing special in this regard. I don't recall -- which Python unit-test frameworks have coverage indications...? Alex
- Previous message (by thread): namespaces & indentation
- Next message (by thread): namespaces & indentation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list