Can't figure out where SyntaxError: can not delete variable 'x' referenced in nested scope us coming from in python >=2.6
Albert Hopkins
marduk at letterboxes.org
Tue Dec 9 13:11:40 EST 2008
Say I have module foo.py:
def a(x):
def b():
x
del x
If I run foo.py under Python 2.4.4 I get:
File "foo.py", line 4
del x
SyntaxError: can not delete variable 'x' referenced in nested
scope
Under Python 2.6 and Python 3.0 I get:
SyntaxError: can not delete variable 'x' referenced in nested
scope
The difference is under Python 2.4 I get a traceback with the lineno and
offending line, but I do not get a traceback in Pythons 2.6 and 3.0.
The reason why I ask is... I have a python package, 'foo', with
__init__.py and a whole bunch of other modules. It runs fine on Python
2.4 as well as 2.6, but when I run 2to3 on my foo directory and try to
'import foo' in Python 3 I get no traceback, I can't 'import foo' in
Python 2 because 'foo' is no longer Python2-compatible, but my original
Python2 version of foo imports just fine.
So is there a way to find the offending code w/o having to go through
every line of code in 'foo' by hand? I've tried using pdb but it just
breaks out of the debugger.
thanks,
-a
More information about the Python-list
mailing list