Issue #23921: Standardized documentation whitespace formatting.

Original patch by James Edwards.
This commit is contained in:
Serhiy Storchaka 2016-05-10 12:01:23 +03:00
parent 387235085c
commit dba903993a
63 changed files with 445 additions and 409 deletions

View file

@ -92,7 +92,7 @@ in the script::
filename = os.environ.get('PYTHONSTARTUP')
if filename and os.path.isfile(filename):
with open(filename) as fobj:
startup_file = fobj.read()
startup_file = fobj.read()
exec(startup_file)

View file

@ -162,12 +162,15 @@ binding::
def scope_test():
def do_local():
spam = "local spam"
def do_nonlocal():
nonlocal spam
spam = "nonlocal spam"
def do_global():
global spam
spam = "global spam"
spam = "test spam"
do_local()
print("After local assignment:", spam)
@ -260,6 +263,7 @@ definition looked like this::
class MyClass:
"""A simple example class"""
i = 12345
def f(self):
return 'hello world'
@ -508,8 +512,10 @@ variable in the class is also ok. For example::
class C:
f = f1
def g(self):
return 'hello world'
h = g
Now ``f``, ``g`` and ``h`` are all attributes of class :class:`C` that refer to
@ -523,8 +529,10 @@ argument::
class Bag:
def __init__(self):
self.data = []
def add(self, x):
self.data.append(x)
def addtwice(self, x):
self.add(x)
self.add(x)
@ -713,7 +721,7 @@ will do nicely::
class Employee:
pass
john = Employee() # Create an empty employee record
john = Employee() # Create an empty employee record
# Fill the fields of the record
john.name = 'John Doe'
@ -839,8 +847,10 @@ defines :meth:`__next__`, then :meth:`__iter__` can just return ``self``::
def __init__(self, data):
self.data = data
self.index = len(data)
def __iter__(self):
return self
def __next__(self):
if self.index == 0:
raise StopIteration

View file

@ -312,7 +312,7 @@ You can see it if you really want to using :func:`print`::
It is simple to write a function that returns a list of the numbers of the
Fibonacci series, instead of printing it::
>>> def fib2(n): # return Fibonacci series up to n
>>> def fib2(n): # return Fibonacci series up to n
... """Return a list containing the Fibonacci series up to n."""
... result = []
... a, b = 0, 1
@ -540,7 +540,7 @@ parameter are 'keyword-only' arguments, meaning that they can only be used as
keywords rather than positional arguments. ::
>>> def concat(*args, sep="/"):
... return sep.join(args)
... return sep.join(args)
...
>>> concat("earth", "mars", "venus")
'earth/mars/venus'

View file

@ -170,15 +170,15 @@ reference ``.args``. One may also instantiate an exception first before
raising it and add any attributes to it as desired. ::
>>> try:
... raise Exception('spam', 'eggs')
... raise Exception('spam', 'eggs')
... except Exception as inst:
... print(type(inst)) # the exception instance
... print(inst.args) # arguments stored in .args
... print(inst) # __str__ allows args to be printed directly,
... # but may be overridden in exception subclasses
... x, y = inst.args # unpack args
... print('x =', x)
... print('y =', y)
... print(type(inst)) # the exception instance
... print(inst.args) # arguments stored in .args
... print(inst) # __str__ allows args to be printed directly,
... # but may be overridden in exception subclasses
... x, y = inst.args # unpack args
... print('x =', x)
... print('y =', y)
...
<class 'Exception'>
('spam', 'eggs')

View file

@ -338,11 +338,11 @@ beginning of the file as the reference point. ::
>>> f = open('workfile', 'rb+')
>>> f.write(b'0123456789abcdef')
16
>>> f.seek(5) # Go to the 6th byte in the file
>>> f.seek(5) # Go to the 6th byte in the file
5
>>> f.read(1)
b'5'
>>> f.seek(-3, 2) # Go to the 3rd byte before the end
>>> f.seek(-3, 2) # Go to the 3rd byte before the end
13
>>> f.read(1)
b'd'

View file

@ -232,7 +232,7 @@ If you want to concatenate variables or a variable and a literal, use ``+``::
This feature is particularly useful when you want to break long strings::
>>> text = ('Put several strings within parentheses '
'to have them joined together.')
... 'to have them joined together.')
>>> text
'Put several strings within parentheses to have them joined together.'
@ -276,11 +276,11 @@ makes sure that ``s[:i] + s[i:]`` is always equal to ``s``::
Slice indices have useful defaults; an omitted first index defaults to zero, an
omitted second index defaults to the size of the string being sliced. ::
>>> word[:2] # character from the beginning to position 2 (excluded)
>>> word[:2] # character from the beginning to position 2 (excluded)
'Py'
>>> word[4:] # characters from position 4 (included) to the end
>>> word[4:] # characters from position 4 (included) to the end
'on'
>>> word[-2:] # characters from the second-last (included) to the end
>>> word[-2:] # characters from the second-last (included) to the end
'on'
One way to remember how slices work is to think of the indices as pointing

View file

@ -34,7 +34,7 @@ called :file:`fibo.py` in the current directory with the following contents::
a, b = b, a+b
print()
def fib2(n): # return Fibonacci series up to n
def fib2(n): # return Fibonacci series up to n
result = []
a, b = 0, 1
while b < n:

View file

@ -301,7 +301,7 @@ file::
with self.assertRaises(TypeError):
average(20, 30, 70)
unittest.main() # Calling from the command line invokes all tests
unittest.main() # Calling from the command line invokes all tests
.. _tut-batteries-included:

View file

@ -180,6 +180,7 @@ tasks in background while the main program continues to run::
threading.Thread.__init__(self)
self.infile = infile
self.outfile = outfile
def run(self):
f = zipfile.ZipFile(self.outfile, 'w', zipfile.ZIP_DEFLATED)
f.write(self.infile)