translating PHP to Python
Xavier Morel
xavier.morel at masklinn.net
Sun Feb 5 14:00:59 EST 2006
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 what that value will return, so
> I can't just manipulate that value as a string.
>
Type doesn't return a string, it returns a reference to a class object.
You look like you want to test if the class of an object is <some
specific class>. For that purpose, check isinstance.
> Is there a simple way to get the current object's name? You would think
> __name__ would work, right? It doesn't.
>
What do you call "the current object's name"? A python object usually
has no name per se (only functions and classes do have one I think).
> Now here's another, similar one:
>
> You can reference an object's parent object directly in PHP, like so:
>
> //note the charming use of semi-colon. isn't it cute?
> parent::__construct(
> $stuffInAWeirdSyntaxThatDoesntMeanAnythingWhenYouReadIt);
>
> 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, do ...stuff!"
>
> Thanks!
>
I guess it's a parent in the inheritance meaning of the term. If so, you
can use either the call-by-class syntax or the `super` construct.
For the call-by-class, see the Python tutorial, chapter 9.5
"Inheritance", last paragraph. For the `super` construct, check the help
on the subject, and the document "Unifying types and classes in Python
2.2" by the BDFL (http://www.python.org/2.2.3/descrintro.html)
More information about the Python-list
mailing list