[issue4246] execution model - clear and complete example in documentation

Terry J. Reedy report at bugs.python.org
Fri Nov 7 21:38:33 CET 2008


Terry J. Reedy <tjreedy at udel.edu> added the comment:

Your example seem too verbose and diffuse.  Perhaps something more
focused on what people do wrong would be more helpful.  I presume you
mean something like this -- with or without x=2 before the def.

>>> def f():
	print (x)
	x = 1

>>> f()
Traceback (most recent call last):
  File "<pyshell#31>", line 1, in <module>
    f()
  File "<pyshell#30>", line 2, in f
    print (x)
UnboundLocalError: local variable 'x' referenced before assignment

What are the other ways people get the error.

----------
nosy: +tjreedy

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4246>
_______________________________________


More information about the Python-bugs-list mailing list