structs in python

Gerhard Häring gerhard.haering at gmx.de
Mon Jul 8 02:09:20 EDT 2002


* Christopher A. Craig <list-python at ccraig.org> [2002-07-08 01:22 -0400]:
> "Kevin O'Connor" <kevin at koconnor.net> writes:
> 
> > What if a syntax like the following were permitted:
> > >>> p = ( .x = 10, .y = 11, .color = 'blue')
> > >>> print p.x
> > 10
> > >>>
> 
> Why don't you just use a dict?  
> 
> >>> p = {'x'=10, 'y'=11, 'color'=blue}
> >>> print p['x']
> 10
> >>>
 
I prefer tiny data-only classes. These can be used exactly like a a
struct.

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))





More information about the Python-list mailing list