[wxPython-users] Best practice to rganize the code
Nigel Rowe
rho at fisheggs.name
Wed Mar 19 02:27:30 PDT 2008
On Tue, 18 Mar 2008 16:53:08 +0100,
"Tim van der Leeuw" <tnleeuw at gmail.com> wrote in a message
with the id <c1f38650803180853p72145494x32c87a22cb5a2c9 at mail.gmail.com>:
>
> On Tue, Mar 18, 2008 at 4:49 PM, Peter Damoc <pdamoc at gmail.com> wrote:
> > :) I think that should be:
> >
> > self.__dict__.update(locals())
> >
> > :)
>
> No, I wanted to add all variables accessible via 'self' to the
> locals, which I think is correct the way I wrote it.
>
> ;-)
>
> Cheers,
>
> --Tim
>
I suspect that Peter said what he did, because your code wouldn't work
anyway.
From the manual:
locals()
Update and return a dictionary representing the current local
symbol table. Warning: The contents of this dictionary should not be
modified; changes may not affect the values of local variables used by
the interpreter.
Note the warning.
And a quick experiment
$ cat foo.py
def foo():
some_dict= {'before':'new value',
'after':'some other value' }
before='this is the value before trying to update locals()'
locals().update(some_dict)
print before
print after
foo()
$ python foo.py
this is the value before trying to update locals()
Traceback (most recent call last):
File "foo.py", line 9, in <module>
foo()
File "foo.py", line 7, in foo
print after
NameError: global name 'after' is not defined
$
--
Nigel Rowe
rho \N{COMMERCIAL AT} fisheggs \N{FULL STOP} name
More information about the wxpython-users
mailing list