Pythonic style involves lots of lightweight classes (for me)

metaperl metaperl at gmail.com
Thu Dec 14 02:07:37 EST 2006


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.




More information about the Python-list mailing list