Re: translating PHP to Python

2006-02-05 Thread Eric Nieuwland
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

Re: translating PHP to Python

2006-02-05 Thread Dave
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

Re: translating PHP to Python

2006-02-05 Thread Terry Hancock
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

Re: translating PHP to Python

2006-02-05 Thread Peter Hansen
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

Re: translating PHP to Python

2006-02-05 Thread Xavier Morel
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

Re: translating PHP to Python

2006-02-05 Thread Magnus Lycka
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

Re: translating PHP to Python

2006-02-05 Thread Magnus Lycka
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

Re: translating PHP to Python

2006-02-05 Thread Peter Hansen
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

Re: translating PHP to Python

2006-02-05 Thread Dave
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()

Re: translating PHP to Python

2006-02-05 Thread Farshid Lashkari
> 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,

translating PHP to Python

2006-02-05 Thread Dave
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,