NameError: global name 'btn_Matlab' is not defined ?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Tue Dec 28 09:15:41 EST 2010
On Tue, 28 Dec 2010 14:34:19 +0100, Stef Mientki wrote:
> hello,
>
> Never seen this before and I've no explanation whatsoever (Python 2.6)
>
> I've some dynamic generated code,
> one of objects generated is a wx.Button, called 'btn_Matlab'.
How do you generate the code?
What code is generated? What does it do?
> After the code is generated, I can see that the button is created in the
> local namespace
>
> print locals()['btn_Matlab']
>
> <wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at
> 0x3602d28> >
>
> but if I try to print the button (at exactly the same location), I get
> an error
>
> print btn_Matlab
>
> NameError: global name 'btn_Matlab' is not defined ?
>
> Why isn't the compiler first checking the local namespace ? any clues ?
My guess is that you've declared btn_Matlab as global, and then
dynamically created a local with the same name using exec or similar.
--
Steven
More information about the Python-list
mailing list