summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-05-10 09:01:56 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-05-10 09:01:56 (GMT)
commitc499f30286976410be13c8476408531bb21631ce (patch)
tree86b8972b6663726a50d716bb13773171f1ca425a /Doc/tutorial
parenta4dfbe608fb52191b435c5545e8a343586887135 (diff)
parentdba903993a8d3e13d2cf83d6a8912e908025b17b (diff)
downloadcpython-c499f30286976410be13c8476408531bb21631ce.zip
cpython-c499f30286976410be13c8476408531bb21631ce.tar.gz
cpython-c499f30286976410be13c8476408531bb21631ce.tar.bz2
Issue #23921: Standardized documentation whitespace formatting.
Original patch by James Edwards.
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/appendix.rst2
-rw-r--r--Doc/tutorial/classes.rst12
-rw-r--r--Doc/tutorial/controlflow.rst4
-rw-r--r--Doc/tutorial/errors.rst16
-rw-r--r--Doc/tutorial/inputoutput.rst4
-rw-r--r--Doc/tutorial/introduction.rst8
-rw-r--r--Doc/tutorial/modules.rst2
-rw-r--r--Doc/tutorial/stdlib.rst2
-rw-r--r--Doc/tutorial/stdlib2.rst1
9 files changed, 31 insertions, 20 deletions
diff --git a/Doc/tutorial/appendix.rst b/Doc/tutorial/appendix.rst
index e04459b..ffd16aa 100644
--- a/Doc/tutorial/appendix.rst
+++ b/Doc/tutorial/appendix.rst
@@ -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)
diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst
index 7e014ef..cc2c35b 100644
--- a/Doc/tutorial/classes.rst
+++ b/Doc/tutorial/classes.rst
@@ -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
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst
index 8453796..9a13d08 100644
--- a/Doc/tutorial/controlflow.rst
+++ b/Doc/tutorial/controlflow.rst
@@ -315,7 +315,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
@@ -543,7 +543,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'
diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst
index 351ee52..4195c7e 100644
--- a/Doc/tutorial/errors.rst
+++ b/Doc/tutorial/errors.rst
@@ -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')
diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst
index 686b2b1..beeaac3 100644
--- a/Doc/tutorial/inputoutput.rst
+++ b/Doc/tutorial/inputoutput.rst
@@ -339,11 +339,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'
diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst
index 87f0fa5..7e8ee3e 100644
--- a/Doc/tutorial/introduction.rst
+++ b/Doc/tutorial/introduction.rst
@@ -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
diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst
index 5fbd879..261a3f3 100644
--- a/Doc/tutorial/modules.rst
+++ b/Doc/tutorial/modules.rst
@@ -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:
diff --git a/Doc/tutorial/stdlib.rst b/Doc/tutorial/stdlib.rst
index 7288873..1dd06c2 100644
--- a/Doc/tutorial/stdlib.rst
+++ b/Doc/tutorial/stdlib.rst
@@ -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:
diff --git a/Doc/tutorial/stdlib2.rst b/Doc/tutorial/stdlib2.rst
index 71194b0..bf4cf87 100644
--- a/Doc/tutorial/stdlib2.rst
+++ b/Doc/tutorial/stdlib2.rst
@@ -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)