[wxPython-users] Best practice to rganize the code

Robin Dunn robin at alldunn.com
Wed Mar 19 17:50:48 PDT 2008


Nigel Rowe wrote:
> 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.

IIRC this is because Python optimizes access to the local variables in 
such a way that it is even quicker than doing a dictionary lookup. 
That's why you'll see people doing things like this:

	foo = self.foo
	# ...do a bunch of stuff with foo...
	
to optimize code that needs a speed boost.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list