Newbie Question: Giving names to Elements of List/Tuple/Dict

Duncan Booth duncan at rcp.co.uk
Fri Nov 29 10:53:45 EST 2002


Oren Tirosh <oren-py-l at hishome.net> wrote in news:mailman.1038579643.30978.python-list at python.org:

>> My question now is, how can I assign names to the elements? Or is there
>> a better way of doing this? 
> 
> Many Python programmers use an empty class for this:
> 
Or a nearly empty class if you want to be lazier when creating
the objects:

>>> class Struct:
	def __init__(self, **args):
		vars(self).update(args)

		
>>> s = Struct(name="Duncan", email="me at somewhere")
>>> s.name
'Duncan'
>>> s.email
'me at somewhere'
>>> 



More information about the Python-list mailing list