Good style for multi-valued returns

Blake Winton bwinton at tor.dhs.org
Mon May 1 23:42:34 EDT 2000


On 21 Apr 2000 17:02:57 GMT, Aahz Maruch wrote:
>In article <43E1059BD6C613C1.19161A8DC1C439F1.3E710DAA95C4F8D8 at lp.airnews.net>,
>Cameron Laird <claird at starbase.neosoft.com> wrote:
>>I think I still have special cases where I want to move dictionaries
>>around, but I'm learning that their proper domain is much smaller than
>>I used to believe.
>
>Well, yeah.  For passing information around, dictionaries are
>appropriate when the key/value linkage is external rather than an
>artifact of your program logic -- basically using a dict as an in-memory
>database.  In addition, I find dictionaries extremely useful for
>managing % strings.

Wow, I just realized that this could totally make some Java code I've
used totally obsolete.  In an app I was writing, we used token-inflation
to fill in values from web pages, but if we could have stuffed the data
into dictionaries (which we did anyways), then having the "%" operation
would have made a 20-30 line class into a one character operator.

>>> dict = {"a":"aa", "b":"bb", "c":"cc"}
>>> string = "%(a)s - %(b)s - %(c)s"
>>> string
'%(a)s - %(b)s - %(c)s'
>>> string % dict
'aa - bb - cc'

And that's why Python is so cool.

Later,
Blake.
-- 
9:48pm up 10 days, 1:58, 1 user, load average: 0.23, 0.05, 0.02



More information about the Python-list mailing list