Concrete classes -- stylistic question
Aahz
aahz at pythoncraft.com
Thu Oct 10 12:30:11 EDT 2002
More information about the Python-list mailing list
Thu Oct 10 12:30:11 EDT 2002
- Previous message (by thread): Strange compiler warning
- Next message (by thread): Concrete classes -- stylistic question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <yu99r8ey47cr.fsf at europa.research.att.com>, 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. > >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 dirt-simple: 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 pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/
- Previous message (by thread): Strange compiler warning
- Next message (by thread): Concrete classes -- stylistic question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list