I wish it was that simple but 'a = Foo().getid()' is actually creating
a new instance of Foo whereas I want the data of the Foo instanced by
__init__ of FooSon().
And as has been mentioned somewhere in this thread, there is no
"instance" of a Foo... only a FooSon, which is being passed up to the
Foo methods for processing.
what I am actually trying to do is to build a set of classes which
handle different type of binary messages coming from the network.
a base message which handles its basic data parts (src, dst, etc.) and
extending it per message type. thus I looked for a way to get the
child calling super for parsing the super's prats and then having the
child parsing its additional details.
And the safest method for that is probably to make sure that any
attributes of the super that must not be shadowed by the subclasses
begin with double underscores... That way, the Python interpreter name
mangles the attribute to avoid collisions.
Compare your initial attempt:
.... def __init__(self):
.... self.me = "Who am I"
.... print "Super: %s" % id(self)
.... .... def __init__(self):
.... super(Sub, self).__init__()
.... self.me = "Where am I"
.... print "Sub: %s" % id(self)
.... Super: 18485328
Sub: 18485328['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__module__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__',
'me']
Note that both self in both Super and Sub is the same ID, and there
is only one "me"...
vs what you get using __attr in the classes
.... def __init__(self):
.... self.__me = "Who am I"
.... print "Super: %s" % id(self)
.... .... def __init__(self):
.... super(Sub, self).__init__()
.... self.__me = "Where am I"
.... print "Sub: %s" % id(self)
.... Super: 18640080
Sub: 18640080['_Sub__me', '_Super__me', '__class__', '__delattr__', '__dict__',
'__doc__', '__getattribute__', '__hash__', '__init__', '__module__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__str__', '__weakref__']
Now there are _Super_me and _Sub__me, with different values.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/