Python/Java OOish type question

Huaiyu Zhu hzhu at users.sourceforge.net
Thu Aug 31 14:43:02 EDT 2000


On Thu, 31 Aug 2000 00:35:08 -0700, Kirby Urner <urner at alumni.princeton.edu>
wrote: 
>
>
>Trying to get clear on something.
>
>I want to have a class with lots of operations defined, 
>and thousands of objects which don't carry the overhead 
>of those operations in memory (because they've already 
>been defined and should be the same for every instance).
>

This is how python works:

>>> class A:
...   def m(): pass
... 
>>> a = A()
>>> a.m
<method A.m of A instance at 0x828678c>
>>> A.m = 2
>>> a.m
2


So you see, only references, not copies of methods.

Huaiyu



More information about the Python-list mailing list