passed extra info to repl function
Fredrik Lundh
fredrik at pythonware.com
Mon Oct 29 15:46:53 EST 2001
Michael P. Soulier wrote:
> def replace(match):
> global replacement_dict
> key = match.group(1)
> if replacement_dict.has_key(key):
> return replacement_dict[key]
> else:
> return ''
use default argument binding:
def replace(match, replacement_dict=replacement_dict):
key = match.group(1)
if replacement_dict.has_key(key):
return replacement_dict[key]
else:
return ''
or:
def replace(match, get=replacement_dict.get):
return get(match.group(1), '')
</F>
<!-- (the eff-bot guide to) the python standard library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list