问题
string.Formatter allows the extension of new style formatting with custom conversion types.
Is this possible for the older "%"
-style formatting strings too? Is there a library for this?
回答1:
Maybe
class CustomFormat(object):
def __init__(self, obj):
self.Object = obj
def __str__(self):
return str(self.Object).upper() # your magic goes here...
print "abc%s" % customFormat("hello")
# abcHELLO
来源:https://stackoverflow.com/questions/18394385/extending-string-formatting-with-custom-conversion-types