how do you get the name of a dictionary?

Georg Brandl g.brandl-nospam at gmx.net
Mon Aug 28 16:06:34 EDT 2006


Antoon Pardon wrote:
> 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.

Yes, but they cannot be refered to by that name any longer.

> 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?

If you assign the variable name to an object, as proposed, both.

Georg



More information about the Python-list mailing list