[Python-checkins] r68221 - in python/trunk/Doc: extending/newtypes.rst howto/curses.rst howto/regex.rst howto/sockets.rst howto/unicode.rst library/abc.rst library/collections.rst library/gettext.rst library/multiprocessing.rst library/optparse.rst library/sched.rst library/socket.rst library/xmlrpclib.rst license.rst tutorial/datastructures.rst tutorial/stdlib2.rst whatsnew/2.0.rst whatsnew/2.2.rst whatsnew/2.4.rst whatsnew/2.6.rst
georg.brandl
python-checkins at python.org
Sat Jan 3 22:04:56 CET 2009
Author: georg.brandl
Date: Sat Jan 3 22:04:55 2009
New Revision: 68221
Log:
Remove tabs from the documentation.
Modified:
python/trunk/Doc/extending/newtypes.rst
python/trunk/Doc/howto/curses.rst
python/trunk/Doc/howto/regex.rst
python/trunk/Doc/howto/sockets.rst
python/trunk/Doc/howto/unicode.rst
python/trunk/Doc/library/abc.rst
python/trunk/Doc/library/collections.rst
python/trunk/Doc/library/gettext.rst
python/trunk/Doc/library/multiprocessing.rst
python/trunk/Doc/library/optparse.rst
python/trunk/Doc/library/sched.rst
python/trunk/Doc/library/socket.rst
python/trunk/Doc/library/xmlrpclib.rst
python/trunk/Doc/license.rst
python/trunk/Doc/tutorial/datastructures.rst
python/trunk/Doc/tutorial/stdlib2.rst
python/trunk/Doc/whatsnew/2.0.rst
python/trunk/Doc/whatsnew/2.2.rst
python/trunk/Doc/whatsnew/2.4.rst
python/trunk/Doc/whatsnew/2.6.rst
Modified: python/trunk/Doc/extending/newtypes.rst
==============================================================================
--- python/trunk/Doc/extending/newtypes.rst (original)
+++ python/trunk/Doc/extending/newtypes.rst Sat Jan 3 22:04:55 2009
@@ -840,8 +840,8 @@
previous sections. We will break down the main differences between them. ::
typedef struct {
- PyListObject list;
- int state;
+ PyListObject list;
+ int state;
} Shoddy;
The primary difference for derived type objects is that the base type's object
@@ -854,10 +854,10 @@
static int
Shoddy_init(Shoddy *self, PyObject *args, PyObject *kwds)
{
- if (PyList_Type.tp_init((PyObject *)self, args, kwds) < 0)
- return -1;
- self->state = 0;
- return 0;
+ if (PyList_Type.tp_init((PyObject *)self, args, kwds) < 0)
+ return -1;
+ self->state = 0;
+ return 0;
}
In the :attr:`__init__` method for our type, we can see how to call through to
@@ -876,18 +876,18 @@
PyMODINIT_FUNC
initshoddy(void)
{
- PyObject *m;
+ PyObject *m;
- ShoddyType.tp_base = &PyList_Type;
- if (PyType_Ready(&ShoddyType) < 0)
- return;
-
- m = Py_InitModule3("shoddy", NULL, "Shoddy module");
- if (m == NULL)
- return;
+ ShoddyType.tp_base = &PyList_Type;
+ if (PyType_Ready(&ShoddyType) < 0)
+ return;
+
+ m = Py_InitModule3("shoddy", NULL, "Shoddy module");
+ if (m == NULL)
+ return;
- Py_INCREF(&ShoddyType);
- PyModule_AddObject(m, "Shoddy", (PyObject *) &ShoddyType);
+ Py_INCREF(&ShoddyType);
+ PyModule_AddObject(m, "Shoddy", (PyObject *) &ShoddyType);
}
Before calling :cfunc:`PyType_Ready`, the type structure must have the
@@ -1167,7 +1167,7 @@
typedef struct PyMethodDef {
char *ml_name; /* method name */
PyCFunction ml_meth; /* implementation function */
- int ml_flags; /* flags */
+ int ml_flags; /* flags */
char *ml_doc; /* docstring */
} PyMethodDef;
Modified: python/trunk/Doc/howto/curses.rst
==============================================================================
--- python/trunk/Doc/howto/curses.rst (original)
+++ python/trunk/Doc/howto/curses.rst Sat Jan 3 22:04:55 2009
@@ -297,7 +297,7 @@
could code::
stdscr.addstr(0, 0, "Current mode: Typing mode",
- curses.A_REVERSE)
+ curses.A_REVERSE)
stdscr.refresh()
The curses library also supports color on those terminals that provide it, The
Modified: python/trunk/Doc/howto/regex.rst
==============================================================================
--- python/trunk/Doc/howto/regex.rst (original)
+++ python/trunk/Doc/howto/regex.rst Sat Jan 3 22:04:55 2009
@@ -917,7 +917,7 @@
InternalDate = re.compile(r'INTERNALDATE "'
r'(?P<day>[ 123][0-9])-(?P<mon>[A-Z][a-z][a-z])-'
- r'(?P<year>[0-9][0-9][0-9][0-9])'
+ r'(?P<year>[0-9][0-9][0-9][0-9])'
r' (?P<hour>[0-9][0-9]):(?P<min>[0-9][0-9]):(?P<sec>[0-9][0-9])'
r' (?P<zonen>[-+])(?P<zoneh>[0-9][0-9])(?P<zonem>[0-9][0-9])'
r'"')
Modified: python/trunk/Doc/howto/sockets.rst
==============================================================================
--- python/trunk/Doc/howto/sockets.rst (original)
+++ python/trunk/Doc/howto/sockets.rst Sat Jan 3 22:04:55 2009
@@ -190,33 +190,33 @@
'''
def __init__(self, sock=None):
- if sock is None:
- self.sock = socket.socket(
- socket.AF_INET, socket.SOCK_STREAM)
- else:
- self.sock = sock
+ if sock is None:
+ self.sock = socket.socket(
+ socket.AF_INET, socket.SOCK_STREAM)
+ else:
+ self.sock = sock
def connect(self, host, port):
- self.sock.connect((host, port))
+ self.sock.connect((host, port))
def mysend(self, msg):
- totalsent = 0
- while totalsent < MSGLEN:
- sent = self.sock.send(msg[totalsent:])
- if sent == 0:
- raise RuntimeError, \
- "socket connection broken"
- totalsent = totalsent + sent
+ totalsent = 0
+ while totalsent < MSGLEN:
+ sent = self.sock.send(msg[totalsent:])
+ if sent == 0:
+ raise RuntimeError, \
+ "socket connection broken"
+ totalsent = totalsent + sent
def myreceive(self):
- msg = ''
- while len(msg) < MSGLEN:
- chunk = self.sock.recv(MSGLEN-len(msg))
- if chunk == '':
- raise RuntimeError, \
- "socket connection broken"
- msg = msg + chunk
- return msg
+ msg = ''
+ while len(msg) < MSGLEN:
+ chunk = self.sock.recv(MSGLEN-len(msg))
+ if chunk == '':
+ raise RuntimeError, \
+ "socket connection broken"
+ msg = msg + chunk
+ return msg
The sending code here is usable for almost any messaging scheme - in Python you
send strings, and you can use ``len()`` to determine its length (even if it has
Modified: python/trunk/Doc/howto/unicode.rst
==============================================================================
--- python/trunk/Doc/howto/unicode.rst (original)
+++ python/trunk/Doc/howto/unicode.rst Sat Jan 3 22:04:55 2009
@@ -30,8 +30,8 @@
looking at Apple ][ BASIC programs, published in French-language publications in
the mid-1980s, that had lines like these::
- PRINT "FICHIER EST COMPLETE."
- PRINT "CARACTERE NON ACCEPTE."
+ PRINT "FICHIER EST COMPLETE."
+ PRINT "CARACTERE NON ACCEPTE."
Those messages should contain accents, and they just look wrong to someone who
can read French.
@@ -89,11 +89,11 @@
character with value 0x12ca (4810 decimal). The Unicode standard contains a lot
of tables listing characters and their corresponding code points::
- 0061 'a'; LATIN SMALL LETTER A
- 0062 'b'; LATIN SMALL LETTER B
- 0063 'c'; LATIN SMALL LETTER C
- ...
- 007B '{'; LEFT CURLY BRACKET
+ 0061 'a'; LATIN SMALL LETTER A
+ 0062 'b'; LATIN SMALL LETTER B
+ 0063 'c'; LATIN SMALL LETTER C
+ ...
+ 007B '{'; LEFT CURLY BRACKET
Strictly, these definitions imply that it's meaningless to say 'this is
character U+12ca'. U+12ca is a code point, which represents some particular
@@ -597,19 +597,19 @@
path will return the 8-bit versions of the filenames. For example, assuming the
default filesystem encoding is UTF-8, running the following program::
- fn = u'filename\u4500abc'
- f = open(fn, 'w')
- f.close()
-
- import os
- print os.listdir('.')
- print os.listdir(u'.')
+ fn = u'filename\u4500abc'
+ f = open(fn, 'w')
+ f.close()
+
+ import os
+ print os.listdir('.')
+ print os.listdir(u'.')
will produce the following output::
- amk:~$ python t.py
- ['.svn', 'filename\xe4\x94\x80abc', ...]
- [u'.svn', u'filename\u4500abc', ...]
+ amk:~$ python t.py
+ ['.svn', 'filename\xe4\x94\x80abc', ...]
+ [u'.svn', u'filename\u4500abc', ...]
The first list contains UTF-8-encoded filenames, and the second list contains
the Unicode versions.
@@ -703,26 +703,26 @@
- [ ] Unicode introduction
- [ ] ASCII
- [ ] Terms
- - [ ] Character
- - [ ] Code point
- - [ ] Encodings
- - [ ] Common encodings: ASCII, Latin-1, UTF-8
+ - [ ] Character
+ - [ ] Code point
+ - [ ] Encodings
+ - [ ] Common encodings: ASCII, Latin-1, UTF-8
- [ ] Unicode Python type
- - [ ] Writing unicode literals
- - [ ] Obscurity: -U switch
- - [ ] Built-ins
- - [ ] unichr()
- - [ ] ord()
- - [ ] unicode() constructor
- - [ ] Unicode type
- - [ ] encode(), decode() methods
+ - [ ] Writing unicode literals
+ - [ ] Obscurity: -U switch
+ - [ ] Built-ins
+ - [ ] unichr()
+ - [ ] ord()
+ - [ ] unicode() constructor
+ - [ ] Unicode type
+ - [ ] encode(), decode() methods
- [ ] Unicodedata module for character properties
- [ ] I/O
- - [ ] Reading/writing Unicode data into files
- - [ ] Byte-order marks
- - [ ] Unicode filenames
+ - [ ] Reading/writing Unicode data into files
+ - [ ] Byte-order marks
+ - [ ] Unicode filenames
- [ ] Writing Unicode programs
- - [ ] Do everything in Unicode
- - [ ] Declaring source code encodings (PEP 263)
+ - [ ] Do everything in Unicode
+ - [ ] Declaring source code encodings (PEP 263)
- [ ] Other issues
- - [ ] Building Python (UCS2, UCS4)
+ - [ ] Building Python (UCS2, UCS4)
Modified: python/trunk/Doc/library/abc.rst
==============================================================================
--- python/trunk/Doc/library/abc.rst (original)
+++ python/trunk/Doc/library/abc.rst Sat Jan 3 22:04:55 2009
@@ -43,15 +43,15 @@
Register *subclass* as a "virtual subclass" of this ABC. For
example::
- from abc import ABCMeta
+ from abc import ABCMeta
- class MyABC:
- __metaclass__ = ABCMeta
+ class MyABC:
+ __metaclass__ = ABCMeta
- MyABC.register(tuple)
+ MyABC.register(tuple)
- assert issubclass(tuple, MyABC)
- assert isinstance((), MyABC)
+ assert issubclass(tuple, MyABC)
+ assert isinstance((), MyABC)
You can also override this method in an abstract base class:
Modified: python/trunk/Doc/library/collections.rst
==============================================================================
--- python/trunk/Doc/library/collections.rst (original)
+++ python/trunk/Doc/library/collections.rst Sat Jan 3 22:04:55 2009
@@ -53,7 +53,7 @@
:class:`Hashable` ``__hash__``
:class:`Iterable` ``__iter__``
:class:`Iterator` :class:`Iterable` ``__next__`` ``__iter__``
-:class:`Sized` ``__len__``
+:class:`Sized` ``__len__``
:class:`Callable` ``__call__``
:class:`Sequence` :class:`Sized`, ``__getitem__`` ``__contains__``. ``__iter__``, ``__reversed__``.
@@ -80,7 +80,7 @@
:class:`MutableMapping` :class:`Mapping` ``__getitem__`` Inherited Mapping methods and
``__setitem__``, ``pop``, ``popitem``, ``clear``, ``update``,
``__delitem__``, and ``setdefault``
- ``__iter__``, and
+ ``__iter__``, and
``__len__``
:class:`MappingView` :class:`Sized` ``__len__``
@@ -96,7 +96,7 @@
size = None
if isinstance(myvar, collections.Sized):
- size = len(myvar)
+ size = len(myvar)
Several of the ABCs are also useful as mixins that make it easier to develop
classes supporting container APIs. For example, to write a class supporting
Modified: python/trunk/Doc/library/gettext.rst
==============================================================================
--- python/trunk/Doc/library/gettext.rst (original)
+++ python/trunk/Doc/library/gettext.rst Sat Jan 3 22:04:55 2009
@@ -648,10 +648,9 @@
animals = ['mollusk',
'albatross',
- 'rat',
- 'penguin',
- 'python',
- ]
+ 'rat',
+ 'penguin',
+ 'python', ]
# ...
for a in animals:
print a
@@ -666,10 +665,9 @@
animals = [_('mollusk'),
_('albatross'),
- _('rat'),
- _('penguin'),
- _('python'),
- ]
+ _('rat'),
+ _('penguin'),
+ _('python'), ]
del _
@@ -692,10 +690,9 @@
animals = [N_('mollusk'),
N_('albatross'),
- N_('rat'),
- N_('penguin'),
- N_('python'),
- ]
+ N_('rat'),
+ N_('penguin'),
+ N_('python'), ]
# ...
for a in animals:
Modified: python/trunk/Doc/library/multiprocessing.rst
==============================================================================
--- python/trunk/Doc/library/multiprocessing.rst (original)
+++ python/trunk/Doc/library/multiprocessing.rst Sat Jan 3 22:04:55 2009
@@ -37,7 +37,7 @@
>>> from multiprocessing import Pool
>>> p = Pool(5)
>>> def f(x):
- ... return x*x
+ ... return x*x
...
>>> p.map(f, [1,2,3])
Process PoolWorker-1:
Modified: python/trunk/Doc/library/optparse.rst
==============================================================================
--- python/trunk/Doc/library/optparse.rst (original)
+++ python/trunk/Doc/library/optparse.rst Sat Jan 3 22:04:55 2009
@@ -548,8 +548,8 @@
:class:`OptionGroup` to a parser is easy::
group = OptionGroup(parser, "Dangerous Options",
- "Caution: use these options at your own risk. "
- "It is believed that some of them bite.")
+ "Caution: use these options at your own risk. "
+ "It is believed that some of them bite.")
group.add_option("-g", action="store_true", help="Group option.")
parser.add_option_group(group)
@@ -563,12 +563,12 @@
-q, --quiet be vewwy quiet (I'm hunting wabbits)
-fFILE, --file=FILE write output to FILE
-mMODE, --mode=MODE interaction mode: one of 'novice', 'intermediate'
- [default], 'expert'
+ [default], 'expert'
Dangerous Options:
- Caution: use of these options is at your own risk. It is believed that
- some of them bite.
- -g Group option.
+ Caution: use of these options is at your own risk. It is believed that
+ some of them bite.
+ -g Group option.
.. _optparse-printing-version-string:
Modified: python/trunk/Doc/library/sched.rst
==============================================================================
--- python/trunk/Doc/library/sched.rst (original)
+++ python/trunk/Doc/library/sched.rst Sat Jan 3 22:04:55 2009
@@ -58,7 +58,7 @@
... print time.time()
... Timer(5, print_time, ()).start()
... Timer(10, print_time, ()).start()
- ... time.sleep(11) # sleep while time-delay events execute
+ ... time.sleep(11) # sleep while time-delay events execute
... print time.time()
...
>>> print_some_times()
Modified: python/trunk/Doc/library/socket.rst
==============================================================================
--- python/trunk/Doc/library/socket.rst (original)
+++ python/trunk/Doc/library/socket.rst Sat Jan 3 22:04:55 2009
@@ -852,20 +852,21 @@
HOST = None # Symbolic name meaning all available interfaces
PORT = 50007 # Arbitrary non-privileged port
s = None
- for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
+ for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,
+ socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
af, socktype, proto, canonname, sa = res
try:
- s = socket.socket(af, socktype, proto)
+ s = socket.socket(af, socktype, proto)
except socket.error, msg:
- s = None
- continue
+ s = None
+ continue
try:
- s.bind(sa)
- s.listen(1)
+ s.bind(sa)
+ s.listen(1)
except socket.error, msg:
- s.close()
- s = None
- continue
+ s.close()
+ s = None
+ continue
break
if s is None:
print 'could not open socket'
@@ -890,16 +891,16 @@
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
- s = socket.socket(af, socktype, proto)
+ s = socket.socket(af, socktype, proto)
except socket.error, msg:
- s = None
- continue
+ s = None
+ continue
try:
- s.connect(sa)
+ s.connect(sa)
except socket.error, msg:
- s.close()
- s = None
- continue
+ s.close()
+ s = None
+ continue
break
if s is None:
print 'could not open socket'
Modified: python/trunk/Doc/library/xmlrpclib.rst
==============================================================================
--- python/trunk/Doc/library/xmlrpclib.rst (original)
+++ python/trunk/Doc/library/xmlrpclib.rst Sat Jan 3 22:04:55 2009
@@ -560,8 +560,8 @@
self.proxy = proxy
def make_connection(self, host):
self.realhost = host
- h = httplib.HTTP(self.proxy)
- return h
+ h = httplib.HTTP(self.proxy)
+ return h
def send_request(self, connection, handler, request_body):
connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
def send_host(self, connection, host):
Modified: python/trunk/Doc/license.rst
==============================================================================
--- python/trunk/Doc/license.rst (original)
+++ python/trunk/Doc/license.rst Sat Jan 3 22:04:55 2009
@@ -453,7 +453,7 @@
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
- http://www.ietf.org/rfc/rfc1321.txt
+ http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
@@ -464,12 +464,12 @@
that follows (in reverse chronological order):
2002-04-13 lpd Removed support for non-ANSI compilers; removed
- references to Ghostscript; clarified derivation from RFC 1321;
- now handles byte order either statically or dynamically.
+ references to Ghostscript; clarified derivation from RFC 1321;
+ now handles byte order either statically or dynamically.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
- added conditionalization for C++ compilation from Martin
- Purschke <purschke at bnl.gov>.
+ added conditionalization for C++ compilation from Martin
+ Purschke <purschke at bnl.gov>.
1999-05-03 lpd Original version.
Modified: python/trunk/Doc/tutorial/datastructures.rst
==============================================================================
--- python/trunk/Doc/tutorial/datastructures.rst (original)
+++ python/trunk/Doc/tutorial/datastructures.rst Sat Jan 3 22:04:55 2009
@@ -251,7 +251,7 @@
[]
>>> [[x,x**2] for x in vec]
[[2, 4], [4, 16], [6, 36]]
- >>> [x, x**2 for x in vec] # error - parens required for tuples
+ >>> [x, x**2 for x in vec] # error - parens required for tuples
File "<stdin>", line 1, in ?
[x, x**2 for x in vec]
^
Modified: python/trunk/Doc/tutorial/stdlib2.rst
==============================================================================
--- python/trunk/Doc/tutorial/stdlib2.rst (original)
+++ python/trunk/Doc/tutorial/stdlib2.rst Sat Jan 3 22:04:55 2009
@@ -62,7 +62,7 @@
>>> locale.format("%d", x, grouping=True)
'1,234,567'
>>> locale.format("%s%.*f", (conv['currency_symbol'],
- ... conv['frac_digits'], x), grouping=True)
+ ... conv['frac_digits'], x), grouping=True)
'$1,234,567.80'
Modified: python/trunk/Doc/whatsnew/2.0.rst
==============================================================================
--- python/trunk/Doc/whatsnew/2.0.rst (original)
+++ python/trunk/Doc/whatsnew/2.0.rst Sat Jan 3 22:04:55 2009
@@ -281,7 +281,7 @@
# 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 @@
[ 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 @@
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 @@
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 ] )
Modified: python/trunk/Doc/whatsnew/2.2.rst
==============================================================================
--- python/trunk/Doc/whatsnew/2.2.rst (original)
+++ python/trunk/Doc/whatsnew/2.2.rst Sat Jan 3 22:04:55 2009
@@ -295,7 +295,7 @@
class D (B,C):
def save (self):
- # Call superclass .save()
+ # Call superclass .save()
super(D, self).save()
# Save D's private information here
...
Modified: python/trunk/Doc/whatsnew/2.4.rst
==============================================================================
--- python/trunk/Doc/whatsnew/2.4.rst (original)
+++ python/trunk/Doc/whatsnew/2.4.rst Sat Jan 3 22:04:55 2009
@@ -396,10 +396,10 @@
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*
Modified: python/trunk/Doc/whatsnew/2.6.rst
==============================================================================
--- python/trunk/Doc/whatsnew/2.6.rst (original)
+++ python/trunk/Doc/whatsnew/2.6.rst Sat Jan 3 22:04:55 2009
@@ -586,30 +586,30 @@
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)
-
- # Calculate the result
- fact = 1L
- for i in range(1, N+1):
- fact = fact * i
+ "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
- # 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 @@
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 @@
('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 @@
>>> 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,
More information about the Python-checkins
mailing list