Concrete classes -- stylistic question

Aahz aahz at
Thu Oct 10 18:30:11 CEST 2002

In article <yu99r8ey47cr.fsf at>,
Andrew Koenig  <ark at> wrote:
>On a few occasions I've wanted to define ``concrete classes'' --
>classes that are so simple that their structure is their interface.
>For example, I might want a little class to hold (x, y) pairs.
>Of course, I can use a tuple, but then I have to remember the meaning
>of each element.  Moreover, if I want to have (x, y) pairs and (r, theta)
>pairs, I don't have an easy way of checking which one is which in case
>I use the wrong one by accident.
>Of course, I could define little classes like this:
>        class xy(object):
>                def __init__(self, x, y):
>                        self.x, self.y = x, y
>        class rtheta(object):
>                def __init__(self, r, theta):
>                        self.r, self.theta = r, theta

You can also do the dirt-simple:

    class xy: pass
    class rtheta: pass

    foo = xy(); foo.x,foo.y = 1,2

I'm not recommending this, of course.  You can also do the even more

    class Record: pass

    foo = Record(); foo.x,foo.y = 1,2

It all depends on where you want your complexity to lie.
Aahz (aahz at           <*>

Project Vote Smart:

More information about the Python-list mailing list