how do you get the name of a dictionary?

Antoon Pardon apardon at forel.vub.ac.be
Mon Aug 28 03:48:09 EDT 2006


On 2006-08-23, Georg Brandl <g.brandl-nospam at gmx.net> wrote:
> jojoba wrote:
>>> And what im saying is that isnt it silly that we need pass an entire
>>> namespace, when a much simpler notion would be to have each object know
>>> its own name(s) (even if that name doesnt exist).
>> 
>> 
>> please note:  in my above comment, i was completely disregarding any
>> notions of added costs that would be incurred to have such a feature,
>> and that in fact, such costs might actually nullify any other benefits
>> from having such a feature. Purely a what-if idea from a nascent python
>> programmer.
>
> Even from such a point of view, the concept isn't clearly enough defined.
> What name would be assigned to the dict below?
>
> l = [1,2,3]
> a = "some_str"
> l[0] = {'foo': 'bar'}
>
> Some immutable objects, such as small integers, exist only once. Would you
> assign names to them? They're likely to be completely meaningless.
>
> When a name goes out of scope, but the object continues to live (e.g.
> because it's returned by some function), the name is void.

I'm not so sure about that. Local functions can be returned and they
keep their name. Of course it depends on what you mean with the
name of an object. Do you mean the variable name or do you mean
the __name__ attribute?

-- 
Antoon Pardon



More information about the Python-list mailing list