how do you get the name of a dictionary?

Fredrik Lundh fredrik at pythonware.com
Tue Aug 22 14:32:56 EDT 2006


jojoba wrote:

> However, although python's object model does not currently support what
> i am asking for, how difficult would it be to assign a string name(s)
> to an object upon creation (and upon referencing)?

if you want to add additional behaviour to an object, wrap it in custom 
class, or use a subclass.

here's an example:

 >>> class dict_with_title(dict):
...     title = None
...
 >>> d = dict_with_title()
 >>> d.title = "this is the title"
 >>> d["a"] = "hello"
 >>> d
{'a': 'hello'}
 >>> d.title
'this is the title'

</F>




More information about the Python-list mailing list