names()
">

(original) (raw)

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
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?

--
anatoly t.