Skip to content

Commit

Permalink
[#3020] Coding standards: use str.format() everywhere not just in i18…
Browse files Browse the repository at this point in the history
…n strings
  • Loading branch information
Sean Hammond committed Nov 16, 2012
1 parent 22441be commit dfa508a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions doc/coding-standards.rst
Expand Up @@ -178,15 +178,19 @@ Logging

.. _Python's Logging HOWTO: http://docs.python.org/2/howto/logging.html

i18n
----
String Formatting
------------------

Don't use the old `%s` style string formatting, e.g. ``"i am a %s" % sub``.
This kind of string formatting is not helpful for internationalization and is
going away in Python 3.

To construct an internationalised string, use `str.format`_, giving
meaningful names to each replacement field. For example: ::
Use the `new .format() method`_ instead, and give meaningful names to each
replacement field, for example::

_(' ... {foo} ... {bar} ...').format(foo='foo-value', bar='bar-value')

.. _str.format: http://docs.python.org/library/stdtypes.html#str.format
.. _new .format() method: http://docs.python.org/2/library/stdtypes.html#str.format

Docstring Standards
-------------------
Expand Down

0 comments on commit dfa508a

Please sign in to comment.