names

Andrew H. Chatham andrew.spambgone.chatham at duke.edu
Sun Jan 14 21:41:14 EST 2001


On Mon, 15 Jan 2001 01:26:45 GMT, Elliott Chapin <echapin at sympatico.ca> wrote:
>How can I get the name of an object as a string? As a biginner I might
>imagine something like
>
>>>>b=[[1],[2]]
>>>>name(b)
>'b'

You can't. The object doesn't know what it's name is, because the name
corresponds to the reference to the object, not the actual object. It's
sometimes tough to realize that variables don't store objects, they store
references to objects.

So if I do

>>>b = [[1],[2]]
>>>c = b

c and b refer to the same list. If I then tried to hypothetical "name"
function, the list would have no idea whether to say 'c' or 'b'.

Andrew


-- 
Andrew Chatham
Duke University '02
andrew.chatham at duke.edu



More information about the Python-list mailing list