translating PHP to Python

Dave davidworley at gmail.com
Mon Feb 6 00:32:59 EST 2006


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 technospecificalist terminosity) has to be done by passing a
reference to the creator object to the created object.

So:

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 an A!"
        else:
            print "Well, I'm a motherless child. Does that mean I can
kill Macbeth?"

(Bonus points for lame, contrived, and sort of offensive Shakespeare
reference)

The project I'm working on is a CSS preprocessor. Watch this space.
It's totally going to be famous.




More information about the Python-list mailing list