Download:
child 9:738beeb055bc
parent 7:093d5397496b
8:9d27d58afcbb
Anton Shestakov <engored@ya.ru>, Mon, 15 Sep 2014 20:51:49 +0900
Redo formatting sections, add .format().

1 файлов изменено, 66 вставок(+), 31 удалений(-) [+]
python.rst file | annotate | diff | comparison | revisions
--- a/python.rst Mon Sep 15 20:51:13 2014 +0900
+++ b/python.rst Mon Sep 15 20:51:49 2014 +0900
@@ -2,32 +2,10 @@
========
-Formatting %
-------------
-
-.. %, mapping, conversion, min width, precision, length, type
-
-``%[(<name>)]`` *|* ``[#0- +][<min width 0-9*>][.<0-9*>][<length>]dioxXeEfFgGcrs``
-
-``#``
- the value conversion will use the “alternate form” (where defined below)
-
-``0``
- the conversion will be zero padded for numeric values
+Common Format Presentation
+--------------------------
-``-``
- the converted value is left adjusted (overrides the '0' conversion if both
- are given)
-
-``␣``
- (a space) a blank should be left before a positive number (or empty string)
- produced by a signed conversion
-
-``+``
- a sign character ('+' or '-') will precede the conversion (overrides a
- “space” flag)
-
-``d`` ``i``
+``d``
signed integer decimal
``o``
@@ -43,18 +21,75 @@
floating point decimal format
``g`` ``G``
- floating point format. Uses *lowercase*, *uppercase* exponential format if
- exponent is less than -4 or not less than precision, decimal format
- otherwise
+ floating point format, decimal or *lowercase*, *uppercase* exponential
``c``
single character (accepts integer or single character string)
+``s``
+ string
+
+
+Format Presentation for %
+-------------------------
+
+``i``
+ same as ``d``
+
``r``
- string (converts any Python object using repr())
+ same as ``s``, but converts any object using ``repr()``
+
+
+Format Presentation for .format()
+---------------------------------
+
+``b``
+ binary
+
+``n``
+ ``d`` or ``g`` with locale-specific characters
+
+``%``
+ percentage, like ``f``, but multiplies the number by 100 and adds a percent
+ sign
+
+
+Formatting with .format()
+-------------------------
-``s``
- string (converts any Python object using str())
+``"{"[field_name]["!"conversion][":"format_spec]"}"``
+
+format_spec: ``[[fill]align][sign]["#"]["0"][width][","]["."precision][type]``
+
+``<``
+ align to left (default for most objects)
+
+``>``
+ align to right (default for numbers)
+
+``=``
+ padding between sign and digits (``+000000120``, valid only for numbers)
+
+``^``
+ align to center
+
+``+``
+ ``+5`` ``-5``
+
+``-``
+ ``5`` ``-5`` (default)
+
+``␣``
+ (a space) ``␣5`` ``-5``
+
+``#``
+ ``0b`` ``0o`` ``0x``
+
+``0``
+ sign-aware zero-padding for numeric types (like ``{:0=}``)
+
+``,``
+ comma as thousands sparator (l10n: use ``n``)
Column 2