[Tutor] Global/Local confusions
John Abbe
johnca@ourpla.net
Tue Mar 4 03:08:02 2003
In my continuing effort to understand global / local interactions --
========================================
#!/usr/local/bin/python
"""
Running this file generates this error:
Traceback (most recent call last):
File "./gltest", line 10, in ?
f(9)
File "./gltest", line 6, in f
if x in b:
UnboundLocalError: local variable 'b' referenced before assignment
"""
b = [9, 10]
def f(x):
if x in b:
print "spam"
b = [11, 12] # if this line is commented out, there's no error!
f(9)
========================================
Any explanations? Life,
John
--
All you /\/\ John Abbe "If you don't like the news,
need \ / CatHerder go out and make some of your own."
is... \/ http://ourpla.net/john/ --Wes Nisker