Lines Matching +full:expand +full:- +full:brackets
1 .. _tut-io:
8 in a human-readable form, or written to a file for future use. This chapter will
12 .. _tut-formatting:
23 printing space-separated values. There are several ways to format output.
25 * To use :ref:`formatted string literals <tut-f-strings>`, begin a string
47 >>> '{:-9} YES votes {:2.2%}'.format(yes_votes, percentage)
60 fairly human-readable, while :func:`repr` is meant to generate representations
97 .. _tut-f-strings:
100 -------------------------
102 :ref:`Formatted string literals <f-strings>` (also called f-strings for
136 The ``=`` specifier can be used to expand an expression to the text of the
145 See :ref:`self-documenting expressions <bpo-36817-whatsnew>` for more information
149 .. _tut-string-format:
152 --------------------------
159 The brackets and characters within them (called format fields) are replaced with
161 brackets can be used to refer to the position of the object passed into the
185 square brackets ``'[]'`` to access the keys. ::
199 This is particularly useful in combination with the built-in function
224 ------------------------
247 The :meth:`str.rjust` method of string objects right-justifies a string in a
252 column lay-out but that's usually better than the alternative, which would be
261 >>> '-3.14'.zfill(7)
262 '-003.14'
268 ---------------------
279 More information can be found in the :ref:`old-string-formatting` section.
282 .. _tut-files:
288 pair: built-in function; open
297 >>> f = open('workfile', 'w', encoding="utf-8")
317 Because UTF-8 is the modern de-facto standard, ``encoding="utf-8"`` is
323 In text mode, the default when reading is to convert platform-specific line
326 platform-specific line endings. This behind-the-scenes modification
335 equivalent :keyword:`try`\ -\ :keyword:`finally` blocks::
337 >>> with open('workfile', encoding="utf-8") as f:
368 .. _tut-filemethods:
371 -----------------------
422 Other types of objects need to be converted -- either to a string (in text mode)
423 or a bytes object (in binary mode) -- before writing them::
448 >>> f.seek(-3, 2) # Go to the 3rd byte before the end
464 .. _tut-json:
467 ---------------------------------------
513 JSON files must be encoded in UTF-8. Use ``encoding="utf-8"`` when opening
522 :mod:`pickle` - the pickle module
524 Contrary to :ref:`JSON <tut-json>`, *pickle* is a protocol which allows