[Python-checkins] peps: Added some examples from Python's source. Both 'before' (str.format) and
eric.smith
python-checkins at python.org
Mon Aug 24 21:48:18 CEST 2015
https://hg.python.org/peps/rev/ada9f2770917
changeset: 5986:ada9f2770917
user: Eric V. Smith <eric at trueblade.com>
date: Mon Aug 24 15:49:18 2015 -0400
summary:
Added some examples from Python's source. Both 'before' (str.format) and 'after' (f-strings).
files:
pep-0498.txt | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/pep-0498.txt b/pep-0498.txt
--- a/pep-0498.txt
+++ b/pep-0498.txt
@@ -551,6 +551,35 @@
>>> f'{(lambda x: x*2)(3)}'
'6'
+Examples from Python's source code
+==================================
+
+Here are some examples from Python source code that currently use
+str.format(), and how they would look with f-strings. This PEP does
+not recommend wholesale converting to f-strings, these are just
+examples of real-world usages of str.format() and how they'd look if
+written from scratch using f-strings.
+
+Lib/asyncio/locks.py::
+
+ extra = '{},waiters:{}'.format(extra, len(self._waiters))
+ extra = f'{extra},waiters:{len(self._waiters)}'
+
+Lib/configparser.py::
+
+ message.append(" [line {0:2d}]".format(lineno))
+ message.append(f" [line {lineno:2d}]")
+
+Tools/clinic/clinic.py::
+
+ methoddef_name = "{}_METHODDEF".format(c_basename.upper())
+ methoddef_name = f"{c_basename.upper()}_METHODDEF"
+
+python-config.py::
+
+ print("Usage: {0} [{1}]".format(sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr)
+ print(f"Usage: {sys.argv[0]} [{'|'.join('--'+opt for opt in valid_opts)}]", file=sys.stderr)
+
References
==========
--
Repository URL: https://hg.python.org/peps
More information about the Python-checkins
mailing list