On Wed, 31 Oct 2012 21:57:28 +0200, anatoly techtonik <techtonik at gmail.com> wrote: > Here is the code: > > ---[cut]----------------------------- > > DEBUG = [] > FONT_NAMES = [] > > def names(): > if len(DEBUG): > print(len(DEBUG)) > if len(FONT_NAMES): > print(len(FONT_NAMES)) > if len(FONT_NAMES)==0: > FONT_NAMES = "query()" > > names() > ---[cut]----------------------------- > > Here is the output: > > Traceback (most recent call last): > File "globalocal.py", line 13, in <module> > names() > File "globalocal.py", line 8, in names > if len(FONT_NAMES): > UnboundLocalError: local variable 'FONT_NAMES' referenced before assignment > > > As you may see there is inconsistency between handling of line 6 - > "if len(DEBUG):" and line 8 - "if len(FONT_NAMES):". This is very magical > and hard to troubleshoot. I wonder if this message can be improved with a > pointer to the concept on when global variables become local? There is no inconsistency here. Only FONT_NAMES is assigned a value in the local scope. "local variable referenced before assignment" *is* a pointer to the concept of when global variables become local...perhaps there is a better wording, do you have a suggestion? --David
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4