UnboundLocalError on shadowed import

Mathieu Fenniak mathieu.fenniak at gmail.com
Tue Jun 29 20:33:23 CEST 2004

On Tue, 29 Jun 2004 14:18:25 -0400, Brad Clements <bkc at murkworks.com> wrote:
> I was going to file this as a bug in the tracker, but maybe it's not really
> a bug. Poor Python code does what I consider to be unexpected. What's your
> opinion?

It looks to me like the "import sys" inside the function is being
considered assignment to 'sys' (which it is).  Adding 'global sys' to
the beginning of the function makes the first call to sys.exit work
properly, rather than using a local 'sys' variable.

More information about the Python-list mailing list