On Tue, 2008-09-16 at 08:49 -0500, Grant Edwards wrote: > On 2008-09-16, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > > Duncan Booth <[EMAIL PROTECTED]> writes: > > > >> The only relatively common use I can think of where you might want to call > >> a method directly on a literal is to produce a list of strings while being > >> lazy about the typing: > > > > By far the most common is probably 'sep'.join(iterable). > > It's also somewhat common to index into a literal: > > ['one','two','three'][n] > > {1:'one', 2:'two', 7:'seven'}[n] >
Indeed. I use this for setting variables based on hostname on a website. Say, for example, you run on port 80 on one host, but on a test host, you share with several other sites, and run on 8084, you can do the following import socket port = { 'www.example.com': 80, 'dev.example.com': 8084, }[socket.gethostname()] It's a handy idiom. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list