how do you get the name of a dictionary?

Michael Janssen mi.janssen at gmail.com
Wed Aug 23 05:54:18 EDT 2006


jojoba wrote:

> given any dictionary, get a name for it.

You do not want to open your text editor and hardcode the name (neither
as a variable name nor a name-attribute), do you? Your script is
hopefully capable to determine the dict-to-be-displayed from
user-input? Perhaps name of a file to be parsed?

>>> anydict = getTheDamnDict(userinput)
>>> displayTheDamnDict(anydict)

Even when you can display the name of the variable the dictionary is
assigned to you yield 'anydict'. That's not that compelling. When you
really intend to hardcode the variable's name to something meaningful,
how is your script supposed to do sensible work after your work is done
with it?

When you want to have a programm that can display arbitrary
dictionaries you end up with a variable name that is (hopefully ;-)
meaningful in the context of the programm but not meaningful in respect
of the content of the dictionary: at programming-time you can't know
what dictionaries are to be displayed so you don't have meaningful
names. You might want to take the name of the file to be parsed or
something else from userinput as the name of the dict - but the
variables name is the wrong place to store this information. Did I miss
anything?

regards
Michael




More information about the Python-list mailing list