diff options
Diffstat (limited to 'Doc/tutorial/inputoutput.rst')
-rw-r--r-- | Doc/tutorial/inputoutput.rst | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst index bfbc9a6..9352f40 100644 --- a/Doc/tutorial/inputoutput.rst +++ b/Doc/tutorial/inputoutput.rst @@ -127,16 +127,17 @@ Basic usage of the :meth:`str.format` method looks like this:: We are the knights who say "Ni!" The brackets and characters within them (called format fields) are replaced with -the objects passed into the format method. The number in the brackets refers to -the position of the object passed into the format method. :: +the objects passed into the :meth:`~str.format` method. The number in the +brackets refers to the position of the object passed into the +:meth:`~str.format` method. :: >>> print '{0} and {1}'.format('spam', 'eggs') spam and eggs >>> print '{1} and {0}'.format('spam', 'eggs') eggs and spam -If keyword arguments are used in the format method, their values are referred to -by using the name of the argument. :: +If keyword arguments are used in the :meth:`~str.format` method, their values +are referred to by using the name of the argument. :: >>> print 'This {food} is {adjective}.'.format( ... food='spam', adjective='absolutely horrible') @@ -157,7 +158,7 @@ truncates Pi to three places after the decimal. The value of PI is approximately 3.142. Passing an integer after the ``':'`` will cause that field to be a minimum -number of characters wide. This is useful for making tables pretty.:: +number of characters wide. This is useful for making tables pretty. :: >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678} >>> for name, phone in table.items(): @@ -178,7 +179,7 @@ square brackets ``'[]'`` to access the keys :: Jack: 4098; Sjoerd: 4127; Dcab: 8637678 This could also be done by passing the table as keyword arguments with the '**' -notation.:: +notation. :: >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> print 'Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}'.format(**table) @@ -356,9 +357,9 @@ shorter than writing equivalent :keyword:`try`\ -\ :keyword:`finally` blocks:: >>> f.closed True -File objects have some additional methods, such as :meth:`isatty` and -:meth:`truncate` which are less frequently used; consult the Library Reference -for a complete guide to file objects. +File objects have some additional methods, such as :meth:`~file.isatty` and +:meth:`~file.truncate` which are less frequently used; consult the Library +Reference for a complete guide to file objects. .. _tut-pickle: |