mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Remove tabs from the documentation.
This commit is contained in:
parent
c62ef8b4d9
commit
7044b11818
20 changed files with 163 additions and 166 deletions
|
@ -281,7 +281,7 @@ write the following to do it::
|
|||
# containing the substring S.
|
||||
sublist = filter( lambda s, substring=S:
|
||||
string.find(s, substring) != -1,
|
||||
L)
|
||||
L)
|
||||
|
||||
Because of Python's scoping rules, a default argument is used so that the
|
||||
anonymous function created by the :keyword:`lambda` statement knows what
|
||||
|
@ -293,7 +293,7 @@ List comprehensions have the form::
|
|||
|
||||
[ expression for expr in sequence1
|
||||
for expr2 in sequence2 ...
|
||||
for exprN in sequenceN
|
||||
for exprN in sequenceN
|
||||
if condition ]
|
||||
|
||||
The :keyword:`for`...\ :keyword:`in` clauses contain the sequences to be
|
||||
|
@ -368,7 +368,7 @@ instance with an incremented value.
|
|||
def __init__(self, value):
|
||||
self.value = value
|
||||
def __iadd__(self, increment):
|
||||
return Number( self.value + increment)
|
||||
return Number( self.value + increment)
|
||||
|
||||
n = Number(5)
|
||||
n += 3
|
||||
|
@ -852,13 +852,12 @@ the PyXML package::
|
|||
from distutils.core import setup, Extension
|
||||
|
||||
expat_extension = Extension('xml.parsers.pyexpat',
|
||||
define_macros = [('XML_NS', None)],
|
||||
include_dirs = [ 'extensions/expat/xmltok',
|
||||
'extensions/expat/xmlparse' ],
|
||||
sources = [ 'extensions/pyexpat.c',
|
||||
'extensions/expat/xmltok/xmltok.c',
|
||||
'extensions/expat/xmltok/xmlrole.c',
|
||||
]
|
||||
define_macros = [('XML_NS', None)],
|
||||
include_dirs = [ 'extensions/expat/xmltok',
|
||||
'extensions/expat/xmlparse' ],
|
||||
sources = [ 'extensions/pyexpat.c',
|
||||
'extensions/expat/xmltok/xmltok.c',
|
||||
'extensions/expat/xmltok/xmlrole.c', ]
|
||||
)
|
||||
setup (name = "PyXML", version = "0.5.4",
|
||||
ext_modules =[ expat_extension ] )
|
||||
|
|
|
@ -295,7 +295,7 @@ will be used in methods to call a method in the superclass; for example,
|
|||
|
||||
class D (B,C):
|
||||
def save (self):
|
||||
# Call superclass .save()
|
||||
# Call superclass .save()
|
||||
super(D, self).save()
|
||||
# Save D's private information here
|
||||
...
|
||||
|
|
|
@ -396,10 +396,10 @@ single class called :class:`Popen` whose constructor supports a number of
|
|||
different keyword arguments. ::
|
||||
|
||||
class Popen(args, bufsize=0, executable=None,
|
||||
stdin=None, stdout=None, stderr=None,
|
||||
preexec_fn=None, close_fds=False, shell=False,
|
||||
cwd=None, env=None, universal_newlines=False,
|
||||
startupinfo=None, creationflags=0):
|
||||
stdin=None, stdout=None, stderr=None,
|
||||
preexec_fn=None, close_fds=False, shell=False,
|
||||
cwd=None, env=None, universal_newlines=False,
|
||||
startupinfo=None, creationflags=0):
|
||||
|
||||
*args* is commonly a sequence of strings that will be the arguments to the
|
||||
program executed as the subprocess. (If the *shell* argument is true, *args*
|
||||
|
|
|
@ -586,30 +586,30 @@ multiple of 4.
|
|||
|
||||
|
||||
def factorial(queue, N):
|
||||
"Compute a factorial."
|
||||
# If N is a multiple of 4, this function will take much longer.
|
||||
if (N % 4) == 0:
|
||||
time.sleep(.05 * N/4)
|
||||
"Compute a factorial."
|
||||
# If N is a multiple of 4, this function will take much longer.
|
||||
if (N % 4) == 0:
|
||||
time.sleep(.05 * N/4)
|
||||
|
||||
# Calculate the result
|
||||
fact = 1L
|
||||
for i in range(1, N+1):
|
||||
fact = fact * i
|
||||
# Calculate the result
|
||||
fact = 1L
|
||||
for i in range(1, N+1):
|
||||
fact = fact * i
|
||||
|
||||
# Put the result on the queue
|
||||
queue.put(fact)
|
||||
# Put the result on the queue
|
||||
queue.put(fact)
|
||||
|
||||
if __name__ == '__main__':
|
||||
queue = Queue()
|
||||
queue = Queue()
|
||||
|
||||
N = 5
|
||||
N = 5
|
||||
|
||||
p = Process(target=factorial, args=(queue, N))
|
||||
p.start()
|
||||
p.join()
|
||||
p = Process(target=factorial, args=(queue, N))
|
||||
p.start()
|
||||
p.join()
|
||||
|
||||
result = queue.get()
|
||||
print 'Factorial', N, '=', result
|
||||
result = queue.get()
|
||||
print 'Factorial', N, '=', result
|
||||
|
||||
A :class:`Queue` is used to communicate the input parameter *N* and
|
||||
the result. The :class:`Queue` object is stored in a global variable.
|
||||
|
@ -630,12 +630,12 @@ across 5 worker processes and retrieve a list of results::
|
|||
from multiprocessing import Pool
|
||||
|
||||
def factorial(N, dictionary):
|
||||
"Compute a factorial."
|
||||
...
|
||||
"Compute a factorial."
|
||||
...
|
||||
p = Pool(5)
|
||||
result = p.map(factorial, range(1, 1000, 10))
|
||||
for v in result:
|
||||
print v
|
||||
print v
|
||||
|
||||
This produces the following output::
|
||||
|
||||
|
@ -1885,9 +1885,9 @@ changes, or look through the Subversion logs for all the details.
|
|||
('id', 'name', 'type', 'size')
|
||||
|
||||
>>> var = var_type(1, 'frequency', 'int', 4)
|
||||
>>> print var[0], var.id # Equivalent
|
||||
>>> print var[0], var.id # Equivalent
|
||||
1 1
|
||||
>>> print var[2], var.type # Equivalent
|
||||
>>> print var[2], var.type # Equivalent
|
||||
int int
|
||||
>>> var._asdict()
|
||||
{'size': 4, 'type': 'int', 'id': 1, 'name': 'frequency'}
|
||||
|
@ -2046,8 +2046,8 @@ changes, or look through the Subversion logs for all the details.
|
|||
|
||||
>>> list(itertools.product([1,2,3], [4,5,6]))
|
||||
[(1, 4), (1, 5), (1, 6),
|
||||
(2, 4), (2, 5), (2, 6),
|
||||
(3, 4), (3, 5), (3, 6)]
|
||||
(2, 4), (2, 5), (2, 6),
|
||||
(3, 4), (3, 5), (3, 6)]
|
||||
|
||||
The optional *repeat* keyword argument is used for taking the
|
||||
product of an iterable or a set of iterables with themselves,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue