Is there a commas-in-between idiom?
Peter van Kampen
news at p2b.datatailors.com
Thu Nov 9 06:31:12 EST 2006
On 2006-11-08, Gabriel Genellina <gagsl-py at yahoo.com.ar> wrote:
> At Wednesday 8/11/2006 16:51, Peter van Kampen wrote:
>
>>"""
>>A = B = [] # both names will point to the same list
>>"""
>>
>>I've been bitten by this once or twice in the past, but I have always
>>wondered what it was useful for? Can anybody enlighten me?
>
> As an optimization, inside a method, you can bind an instance
> attribute and a local name to the same object:
>
> def some_action(self):
> self.items = items = []
> // following many references to self.items,
> // but using items instead.
>
> Names in the local namespace are resolved at compile time, so using
> items is a lot faster than looking for "items" inside self's
> namespace each time it's used.
Nice example.
Thanks,
PterK
--
Peter van Kampen
pterk -- at -- datatailors.com
More information about the Python-list
mailing list