[Tutor] Getting at object names

Jeff Shannon jeff@ccvcorp.com
Tue Apr 1 14:42:02 2003

Charlie Clark wrote:

>Now I know the last line doesn't work because __name__ isn't an attriubute 
>of the list. But is it possible to get at the name of the list?

Just include the name as part of the dictionary, making the dictionary 
values a tuple of (string, list):

days = {'1': ('friday', []), '2': ('saturday', []), '3': ('sunday', [])}

d = days.keys()
for day in d:
    name, values = days[d]
    print '%s : %s' % (name, values)

Jeff Shannon
Credit International