string formatting with missing dictionary key
Jeff Epler
jepler at unpythonic.net
Mon Jan 13 14:20:31 EST 2003
More information about the Python-list mailing list
Mon Jan 13 14:20:31 EST 2003
- Previous message (by thread): string formatting with missing dictionary key
- Next message (by thread): string formatting with missing dictionary key
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
(Requires Python 2.2)
class D(dict):
def __getitem__(self, item):
if not self.has_key(item): return "default"
return super(D, self).__getitem__(item)
print "%(a)s ; %(d)s; %(e)s" % D({'a':1, 'b':2, 'c':3})
- Previous message (by thread): string formatting with missing dictionary key
- Next message (by thread): string formatting with missing dictionary key
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list