Python evangelists unite!

Kragen Sitaker kragen at pobox.com
Sat Dec 1 04:16:27 EST 2001


<brueckd at tbye.com> writes:
> In truth, all less dynamic languages *wish* they had this
> feature. Since they don't developers instead have two additional pieces of
> work when creating a new class: (1) they have to figure out up front the
> total collection of possible attributes/properties instances can have, and
> (2)  they have to set them to some null-like value if those attrs/props
> are not present. So instead of an instance simply not having a property,
> all other instances have to have a property with a value that means they
> don't have that property. Wow.

I do this all the time in Python, simply because it's easier to write
(and read):

    if self.property is None:
        self.property = self.computeproperty()

than

    try: self.property
    except AttributeError: self.property = self.computeproperty()

or

    if not hasattr(self, 'property'):  # especially when it's __property
        self.property = self.computeproperty()





More information about the Python-list mailing list