[issue10660] format() to lower and uppercase
Eric Smith
report at bugs.python.org
Thu Dec 9 17:53:53 CET 2010
Eric Smith <eric at trueblade.com> added the comment:
I agree with David.
Here's an example of using such a subclass. It extends the format string for strings to begin with an optional 'u' or 'l':
-----------------------
class U(str):
def __format__(self, fmt):
if fmt[0] == 'u':
s = self.upper()
fmt = fmt[1:]
elif fmt[0] == 'l':
s = self.lower()
fmt = fmt[1:]
else:
s = str(self)
return s.__format__(fmt)
name = 'Hervé Cauwelier'
print('{0:u*^20} {0:l*^20} {0:*^20}'.format(U(name)))
-----------------------
It produces:
**HERVÉ CAUWELIER*** **hervé cauwelier*** **Hervé Cauwelier***
----------
nosy: +eric.smith
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10660>
_______________________________________
More information about the Python-bugs-list
mailing list