summaryrefslogtreecommitdiffstats
path: root/Lib/string.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-08-19 21:26:34 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-08-19 21:26:34 (GMT)
commite56bf97ef4283a877c459390516bb7385e8e4ec4 (patch)
treed175af7fff6eeacc8c58a7bdad0a0f546063b292 /Lib/string.py
parent828607170da3986af909defe99f956e5762e4dd0 (diff)
downloadcpython-e56bf97ef4283a877c459390516bb7385e8e4ec4.zip
cpython-e56bf97ef4283a877c459390516bb7385e8e4ec4.tar.gz
cpython-e56bf97ef4283a877c459390516bb7385e8e4ec4.tar.bz2
#13579: teach string.Formatter about 'a'.
Patch by Francisco Martín Brugué.
Diffstat (limited to 'Lib/string.py')
-rw-r--r--Lib/string.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/string.py b/Lib/string.py
index ef0334c..0f4ede2 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -236,12 +236,14 @@ class Formatter:
def convert_field(self, value, conversion):
# do any conversion on the resulting object
- if conversion == 'r':
- return repr(value)
+ if conversion is None:
+ return value
elif conversion == 's':
return str(value)
- elif conversion is None:
- return value
+ elif conversion == 'r':
+ return repr(value)
+ elif conversion == 'a':
+ return ascii(value)
raise ValueError("Unknown conversion specifier {0!s}".format(conversion))