I find it arduous to type dictionary['key'] and also feel that any data
I create for a program deserves to have its operations tied to it. As a
result, I often create lots of lightweight classes. Here's a small
example:


vlc = '/Applications/VLC.app/Contents/MacOS/VLC'

class song(object):
    def __init__(self, title, url):
        self.title = title
        self.url   = url



urls = [
    song(title='breath',
         url='mms://ra.colo.idt.net/ginsburgh/eng/med/breath.mp3'),
    song(title='waking',
         url= 'mms://ra.colo.idt.net/ginsburgh/eng/med/modeh.mp3')
    ]

for url in urls:
    print url.title


.... The above program started out as a list of dictionaries, but I
like the current approach much better.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to