[Tutor] Getting at object names
alan.gauld@bt.com
alan.gauld@bt.com
Tue Apr 1 12:41:08 2003
> friday = []
> saturday = []
> sunday = []
>
> days = {'1': friday, '2': saturday, '3': sunday}
>
> # the lists are then filled
>
> d = days.keys
> d.sort
>
> for day in d:
> print days[day].__name__, days[day],
>
> 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?
No, because its just a symbol in the program (OK you could read the
local namespace dictionary but that's messy and not to be encouraged!
Why not just associate the dayname with the key?
days = {1:('friday',friday),2:('saturday',saturday).....}
for day in d
print days[day][0],days[day][1]
Alan G.