Concrete classes -- stylistic question

Gerhard Häring gerhard.haering at gmx.de
Thu Oct 10 12:47:13 EDT 2002


Aahz wrote in comp.lang.python:
> Andrew Koenig  <ark at research.att.com> 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.
> You can also do the dirt-simple:
> 
>     class xy: pass
> 
>     foo = xy(); foo.x,foo.y = 1,2

I'd suggest:

class Point(object):
    __slots__ = ["x", "y"]

p = Point()
p.x = 5
p.y = 6
p.z = 7 # raises AttributeError

Now who will come up with a neat example using metaclasses?

-- Gerhard



More information about the Python-list mailing list