11.. _tut-io :
22
33****************
4- Input and Output
4+ Input and output
55****************
66
77There are several ways to present the output of a program; data can be printed
@@ -11,7 +11,7 @@ discuss some of the possibilities.
1111
1212.. _tut-formatting :
1313
14- Fancier Output Formatting
14+ Fancier output formatting
1515=========================
1616
1717So far we've encountered two ways of writing values: *expression statements * and
@@ -111,7 +111,7 @@ This syntax is easy to use, although it offers much less control for formatting.
111111
112112.. _tut-f-strings :
113113
114- Formatted String Literals
114+ Formatted string literals
115115-------------------------
116116
117117:ref: `Formatted string literals <f-strings >` (also called f-strings for
@@ -163,7 +163,7 @@ the reference guide for the :ref:`formatspec`.
163163
164164.. _tut-string-format :
165165
166- The String format() Method
166+ The string format() method
167167--------------------------
168168
169169Basic usage of the :meth: `str.format ` method looks like this::
@@ -240,7 +240,7 @@ For a complete overview of string formatting with :meth:`str.format`, see
240240:ref: `formatstrings `.
241241
242242
243- Manual String Formatting
243+ Manual string formatting
244244------------------------
245245
246246Here's the same table of squares and cubes, formatted manually::
@@ -303,20 +303,19 @@ More information can be found in the :ref:`old-string-formatting` section.
303303
304304.. _tut-files :
305305
306- Reading and Writing Files
306+ Reading and writing files
307307=========================
308308
309309.. index ::
310310 pair: built-in function; open
311311 pair: object; file
312312
313313:func: `open ` returns a :term: `file object `, and is most commonly used with
314- two positional arguments and one keyword argument:
315- ``open(filename, mode, encoding=None) ``
314+ two positional arguments: ``open(filename, mode) ``
316315
317316::
318317
319- >>> f = open('workfile', 'w', encoding="utf-8" )
318+ >>> f = open('workfile', 'w')
320319
321320.. XXX str(f) is <io.TextIOWrapper object at 0x82e8dc4>
322321
@@ -334,10 +333,7 @@ omitted.
334333
335334Normally, files are opened in :dfn: `text mode `, that means, you read and write
336335strings from and to the file, which are encoded in a specific *encoding *.
337- If *encoding * is not specified, the default is platform dependent
338- (see :func: `open `).
339- Because UTF-8 is the modern de-facto standard, ``encoding="utf-8" `` is
340- recommended unless you know that you need to use a different encoding.
336+ If *encoding * is not specified, the default is UTF-8 (see :func: `open `).
341337Appending a ``'b' `` to the mode opens the file in :dfn: `binary mode `.
342338Binary mode data is read and written as :class: `bytes ` objects.
343339You can not specify *encoding * when opening file in binary mode.
@@ -356,7 +352,7 @@ after its suite finishes, even if an exception is raised at some
356352point. Using :keyword: `!with ` is also much shorter than writing
357353equivalent :keyword: `try `\ -\ :keyword: `finally ` blocks::
358354
359- >>> with open('workfile', encoding="utf-8" ) as f:
355+ >>> with open('workfile') as f:
360356 ... read_data = f.read()
361357
362358 >>> # We can check that the file has been automatically closed.
@@ -389,7 +385,7 @@ automatically fail. ::
389385
390386.. _tut-filemethods :
391387
392- Methods of File Objects
388+ Methods of file objects
393389-----------------------
394390
395391The rest of the examples in this section will assume that a file object called
@@ -532,8 +528,8 @@ To decode the object again, if ``f`` is a :term:`binary file` or
532528 x = json.load(f)
533529
534530.. note ::
535- JSON files must be encoded in UTF-8. Use `` encoding="utf-8" `` when opening
536- JSON file as a :term: `text file ` for both of reading and writing .
531+ JSON files must be encoded in UTF-8, the default encoding for
532+ :term: `text files <text file> ` .
537533
538534This simple serialization technique can handle lists and dictionaries, but
539535serializing arbitrary class instances in JSON requires a bit of extra effort.
0 commit comments