On 2006-11-08, Gabriel Genellina <[EMAIL PROTECTED]> 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 -- http://mail.python.org/mailman/listinfo/python-list