Message 86214 - Python tracker (original) (raw)

Suggested doc change for LibRef / StringServices / string.... / Format String Syntax

  1. In the grammar box, replace the field_name line with " field_name ::= arg_name ("." attribute_name | "[" element_index "]")* arg_name ::= (identifier | integer)? " The current text ambiguously uses "field_name" for both 'field_name' and 'arg_name'. I found explaining the rule for blank arg_names in field_names easier and clearer with two separate unambiguous terms.

Note: 'element_index' should be linked to its definition just as, for instance, 'attribute_name' is. Currently it is not.

  1. Revise the next two paragraphs as follows (using * to indicate grammar-term italics as in the current text -- except all is just for emphasis): " In less formal terms, the replacement field starts with a field_name that specifies the object whose value is to be formatted and inserted into the output instead of the replacement field. The field_name is optionally followed by a conversion field, which is preceded by an exclamation point '!', and a format_spec, which is preceded by a colon ':'. These specify a non-default format for the replacement value.

The field_name itself begins with an arg_name that is either a number or a keyword. If it’s a number, it refers to a positional argument of the str.format() method, and if it’s a keyword it refers to a named keyword argument. If the numerical arg_names in a format string are 0, 1, 2, ... in sequence, they can all be omitted (not just some) and the numbers 0, 1, 2, ... will be automatically inserted in order. The arg_name can be followed by any number of index or attribute expressions. An expression of the form '.name' selects the named attribute using getattr(), while an expression of the form '[index]' does an index lookup using getitem(). " Note: getattr and getitem should be left linked as in the current text.

  1. In the following examples, add ''' "From {} to {}" # Same as "From {0] to {1}"