Python/Java OOish type question

Calvelo Daniel dcalvelo at pharion.univ-lille2.fr
Thu Aug 31 05:05:52 EDT 2000


Kirby Urner <urner at alumni.princeton.edu> wrote:

: Trying to get clear on something.

[snip]

: I'm NOT getting copies of the 'add' method inside every quat 
: object.  Or am I?  Isn't it the case that quat is basically
: instantiating once, leaving room for 'self' to go through as
: a kind of parameter, different for each object of type quat
: (including subtypes)?

[snip]

: You can get memory references for q1.add and q2.add, but the
: different returns correspond to the locations of q1 and q2 
: as objects -- doesn't tell me whether the add method is 
: actually taking up bytes inside q1 and q2.

:  >>> q1.add
:  <method quat.add of quat instance at 1ae9b00>
:  >>> q2.add
:  <method quat.add of quat instance at 1aeb3d0>
:  >>> q2
:  <__main__.quat instance at 1aeb3d0>

: I may be rather confused here.  Anyone with the patience to 
: help me sort it out?

Well not exactly patience, but this might give you some elements for
further exploration:

>>> class quat:
...      def __init__(self,value):
...          self.value = value
...      def add(self,b):
...          return quat(self.value + b.value)
... 
>>> a1 = quat(1)
>>> a2 = quat(2)
>>> a3 = a1.add(a2)
>>> dir(a1.add)
['__doc__', '__name__', 'im_class', 'im_func', 'im_self']
>>> a1.add.im_func 
<function add at 8080648>
>>> a2.add.im_func 
<function add at 8080648>
>>> a3.add.im_func 
<function add at 8080648>

'im' as 'i'nstance 'm'ethod, I reckon.

HTH, DCA

-- Daniel Calvelo Aros
     calvelo at lifl.fr



More information about the Python-list mailing list