Interpolation (was: Keyword calling gotcha ?)

Evan Simpson evan at tokenexchange.com
Fri May 28 14:12:46 EDT 1999


[It would be nice to be able to interpolate tuples into a parameter list]

Perhaps parameter-list construction syntax could be made symmetrical to
parameter declaration?

Thus:

>>> def sing(bruces, *lyrics, **madlib):
...     for lyric in lyrics:
...         for bruce in bruces:
...             print bruce, lyric % madlib
>>> song = ('Emmanuel Kant was a real %(adj1)s', 'who was very rarely
%(adj2)')
>>> words = {'adj1': 'pissant', 'adj2': 'stable'}
>>> sing(['Bruce', 'Bruce'], *song, **words)
instead of
>>> apply(sing, (['Bruce', 'Bruce'],)+song, words)
or even
>>> nextverse = ('Rene Descartes was a %(adj3)s', 'who could %(verb1)s')
>>> morewords = {'adj3': 'drunken fart', 'verb1': 'drink you under the
table'}
>>> sing(['Eric'], *song, *nextverse, **words, **morewords)
instead of
>>> words.update(morewords)
>>> apply(sing, (['Eric'],)+song+nextverse, words)

or-is-my-philosophy-flawed?-ly y'rs
Evan Simpson






More information about the Python-list mailing list