"%(a)s ... %(b)s" % {'a': foo, 'b': '%(b)s'}

t. middleton t.middleton at news.vex.net
Sat Dec 4 23:24:58 EST 1999


>Can't Python automatticaly detect there's no B so leave it blank?
>Why doesn't Python do this?

Of course, you can easily hack this behavior yourself, if you really,
really, really want to. The following will output 'aaaaa, None' ....
but do you really, really, really, really want to?

import UserDict

class NoneInsteadOfBang(UserDict.UserDict):
    def __getitem__(self, key):
        try:
            return self.data[key]
        except KeyError:
            return None

print '%(a)s, %(b)s' % NoneInsteadOfBang({'a':'aaaaa'})

...






More information about the Python-list mailing list