Dave wrote:
> class A(object):
> def create_child(self):
> self.child = B()
> self.child.do_stuff(self)
>
> class B(object):
> def do_stuff(self, parent):
> self.parent = parent
> if self.parent.__class__.__name__ == 'A':
> print "I'm a child of a
So thanks, all for the help.
Turns out that the solution is simple enough, as are most solutions in
Python:
PHP:
parent::__construct(args)
does translate to the Python:
super(ParentClass, self).__init__(args)
The example, that of referencing an object's creator object (if that's
the technospeci
On Sun, 05 Feb 2006 15:04:32 -0500
Peter Hansen <[EMAIL PROTECTED]> wrote:
> Dave wrote:
> > The second point won't work, though, because by parent
> > class I mean, simply, the object that created the
> > current object, *not* the class the current class is
> > based on.
>
> Good you clarified t
Magnus Lycka wrote:
> Peter Hansen wrote:
>>Good you clarified that, because "parent" definitely isn't used that way
>>by most other people here.
>
> Unless they are coding GUIs? I guess it's pretty common that GUI
> controls are contained in other controls called parents. At least
> that's how
Dave wrote:
> Anyone familiar with PHP? I'm trying to make a translation. In PHP you
> can get the current object's name by going like this:
>
> get_class(item) == 'ClassName'
>
> I've tried type(item), but since I can't be sure if I'll be in __main__
> or as a child object, I can't guarantee wha
Peter Hansen wrote:
> Good you clarified that, because "parent" definitely isn't used that way
> by most other people here.
Unless they are coding GUIs? I guess it's pretty common that GUI
controls are contained in other controls called parents. At least
that's how it's done in wxPython.
--
http
Dave wrote:
> Is there a built in way to do this in Python, or do I have to pass
> "parent" when I init Thing?
While I'm sure you could find a "clever" way to do this, passing
in "parent" explicitly is the "proper" way to do it. Once in a
while, you might actually want some other object than the l
Dave wrote:
> The second point won't work, though, because by parent class I mean,
> simply, the object that created the current object, *not* the class the
> current class is based on.
Good you clarified that, because "parent" definitely isn't used that way
by most other people here. And, in fa
Farshid,
This is a great help, thanks.
The second point won't work, though, because by parent class I mean,
simply, the object that created the current object, *not* the class the
current class is based on.
So, for example:
class A(object):
def __init__(self):
self.thing = Thing()
> Is there a simple way to get the current object's name? You would think
> __name__ would work, right? It doesn't.
className = item.__class__.__name__
> I'd like to avoid passing a reference to an object's parent in
> __init__, but is there a built in way in Python to say "You, Parent
> Object,
Anyone familiar with PHP? I'm trying to make a translation. In PHP you
can get the current object's name by going like this:
get_class(item) == 'ClassName'
I've tried type(item), but since I can't be sure if I'll be in __main__
or as a child object, I can't guarantee what that value will return,
11 matches
Mail list logo