Case insensitive version of string.Template?
python at bdurham.com
python at bdurham.com
Sat May 16 12:37:28 EDT 2009
Gabriel,
<snipped>
If you can guarantee the identifiers are all lowercase inside the
dictionary:
class lowercase_dict(dict):
def __getitem__(self, name):
return dict.__getitem__(self, name.lower())
import string
values = lowercase_dict( name='John Doe', phone='999-555-1212' )
output = string.Template( 'My name is $NAME and my phone is $Phone.'
).safe_substitute( values )
</snipped>
Brilliant!! Using a custom dictionary solves my problem and gives me
some ideas on similar challenges.
Thank you!
Regards,
Malcolm
More information about the Python-list
mailing list