is Python fully object oriented ?

Delaney, Timothy tdelaney at avaya.com
Sun Jan 14 19:59:02 EST 2001


> Note that in the case of attributes that are mutable, you can use
> local variables if you like:
> 
> def method(self):
>     foo = self.foo
>     foo.do_this()
>     foo.do_that()
>     return foo.get_bar() + foo.get_baz()
> 
> and since you prevent extra lookups, may in some cases even speed up 
> your code.
> 
> In the case your attributes are immutable objects, you need 
> to make sure
> they're changed in the end if you use this technique:
> 
> def method(self):
>     foo = self.foo
>     foo = foo + 12
>     ... lots more ..
>     self.foo = foo

Ooh - dangerous in a multithreaded app ... ;)




More information about the Python-list mailing list