translating PHP to Python

Magnus Lycka lycka at carmen.se
Sun Feb 5 17:16:18 EST 2006


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 logical
"parent" to do the object creation.

By the way, you might want to google up "Law of Demeter". While
many good Python programmers bend that rule a bit, it's a good
aspect to have in mind when designing classes and programs.

> Sorry if this is confusing. It confuses me, too. I should have been a
> carpenter.

I'm not so sure. Confused carpenters tend to do really stupid things
like sawing off their fingers... Programming is a lot safer! ;^)



More information about the Python-list mailing list