how do you get the name of a dictionary?

Georg Brandl g.brandl-nospam at gmx.net
Tue Aug 22 13:09:13 EDT 2006


jojoba wrote:
> Hello again,
> 
> Fredrick said:
> 
>> Python's object model.  an object has a value, a type, and an identity,
>> but no name.
> 
> I say:
> 
> Thank you Fredrick for the reply!
> 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)?
> 
> please note:
> i don't want to do anything sophisticated with this, i am really only
> looking for a TITLE for my dictionary when i throw it in a tree editor
> that i have built. And i do realize that its not possible now. I am
> just pressing a point here.
> 
> Sorry to ruffle everyone's feathers, but this is a fairly curious
> problem.

Why not add a "name" attribute to your objects? e.g.

class NamedDict(dict):
     def __init__(self, _name_, *args, **kwargs):
         self.name = _name_
         dict.__init__(self, *args, **kwargs)

Georg



More information about the Python-list mailing list