how do you get the name of a dictionary?
Matimus
mccredie at gmail.com
Fri Aug 18 20:07:13 EDT 2006
You could do something like this:
>>> class MyDict(dict):
... pass
>>> bananna = MyDict({"foo":"bar"}) #dict constructor still works
>>> bananna.name = "bananna"
>>> bananna.name
'bananna'
>>> bananna
{'foo': 'bar'}
Or, you could also just do this:
>>> bananna = {"name":"bananna"}
Depending on what you actually want to use it for the best solution is
to use the id instead of a name though.
-Matt
More information about the Python-list
mailing list