structs in python

Christophe Delord christophe.delord at free.fr
Mon Jul 8 13:29:34 EDT 2002


The dict can be the __dict__ attribute of a particular class :


class Record:

	def __init__(self, **kw):
		self.__dict__.update(kw);

p = Record(x=10, y=11, color='blue')

print p.x



On 07 Jul 2002 23:29:28 -0700
Paul Rubin <phr-n2002b at NOSPAMnightsong.com> wrote:

> list-python at ccraig.org (Christopher A. Craig) writes:
> > Why don't you just use a dict?  
> > 
> > >>> p = {'x'=10, 'y'=11, 'color'=blue}
> > >>> print p['x']
> > 10
> 
> Typing p['x'] is more cumbersome than typing p.x and doesn't convey
> the same type of meaning.  p.x sounds more like it refers to a fixed
> slot in a structure.


-- 

(o_   Christophe Delord                   _o)
//\   http://christophe.delord.free.fr/   /\\
V_/_  mailto:christophe.delord at free.fr   _\_V



More information about the Python-list mailing list