Commit 9afde1c0 authored by Georg Brandl's avatar Georg Brandl

#1370: Finish the merge r58749, log below, by resolving all conflicts in Doc/.

Merged revisions 58221-58741 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r58221 | georg.brandl | 2007-09-20 10:57:59 -0700 (Thu, 20 Sep 2007) | 2 lines

  Patch #1181: add os.environ.clear() method.
........
  r58225 | sean.reifschneider | 2007-09-20 23:33:28 -0700 (Thu, 20 Sep 2007) | 3 lines

  Issue1704287: "make install" fails unless you do "make" first.  Make
     oldsharedmods and sharedmods in "libinstall".
........
  r58232 | guido.van.rossum | 2007-09-22 13:18:03 -0700 (Sat, 22 Sep 2007) | 4 lines

  Patch # 188 by Philip Jenvey.
  Make tell() mark CRLF as a newline.
  With unit test.
........
  r58242 | georg.brandl | 2007-09-24 10:55:47 -0700 (Mon, 24 Sep 2007) | 2 lines

  Fix typo and double word.
........
  r58245 | georg.brandl | 2007-09-24 10:59:28 -0700 (Mon, 24 Sep 2007) | 2 lines

  #1196: document default radix for int().
........
  r58247 | georg.brandl | 2007-09-24 11:08:24 -0700 (Mon, 24 Sep 2007) | 2 lines

  #1177: accept 2xx responses for https too, not only http.
........
  r58249 | andrew.kuchling | 2007-09-24 16:45:51 -0700 (Mon, 24 Sep 2007) | 1 line

  Remove stray odd character; grammar fix
........
  r58250 | andrew.kuchling | 2007-09-24 16:46:28 -0700 (Mon, 24 Sep 2007) | 1 line

  Typo fix
........
  r58251 | andrew.kuchling | 2007-09-24 17:09:42 -0700 (Mon, 24 Sep 2007) | 1 line

  Add various items
........
  r58268 | vinay.sajip | 2007-09-26 22:34:45 -0700 (Wed, 26 Sep 2007) | 1 line

  Change to flush and close logic to fix #1760556.
........
  r58269 | vinay.sajip | 2007-09-26 22:38:51 -0700 (Wed, 26 Sep 2007) | 1 line

  Change to basicConfig() to fix #1021.
........
  r58270 | georg.brandl | 2007-09-26 23:26:58 -0700 (Wed, 26 Sep 2007) | 2 lines

  #1208: document match object's boolean value.
........
  r58271 | vinay.sajip | 2007-09-26 23:56:13 -0700 (Wed, 26 Sep 2007) | 1 line

  Minor date change.
........
  r58272 | vinay.sajip | 2007-09-27 00:35:10 -0700 (Thu, 27 Sep 2007) | 1 line

  Change to LogRecord.__init__() to fix #1206. Note that archaic use of type(x) == types.DictType is because of keeping 1.5.2 compatibility. While this is much less relevant these days, there probably needs to be a separate commit for removing all archaic constructs at the same time.
........
  r58288 | brett.cannon | 2007-09-30 12:45:10 -0700 (Sun, 30 Sep 2007) | 9 lines

  tuple.__repr__ did not consider a reference loop as it is not possible from
  Python code; but it is possible from C.  object.__str__ had the issue of not
  expecting a type to doing something within it's tp_str implementation that
  could trigger an infinite recursion, but it could in C code..  Both found
  thanks to BaseException and how it handles its repr.

  Closes issue #1686386.  Thanks to Thomas Herve for taking an initial stab at
  coming up with a solution.
........
  r58289 | brett.cannon | 2007-09-30 13:37:19 -0700 (Sun, 30 Sep 2007) | 3 lines

  Fix error introduced by r58288; if a tuple is length 0 return its repr and
  don't worry about any self-referring tuples.
........
  r58294 | facundo.batista | 2007-10-02 10:01:24 -0700 (Tue, 02 Oct 2007) | 11 lines


  Made the various is_* operations return booleans.  This was discussed
  with Cawlishaw by mail, and he basically confirmed that to these is_*
  operations, there's no need to return Decimal(0) and Decimal(1) if
  the language supports the False and True booleans.

  Also added a few tests for the these functions in extra.decTest, since
  they are mostly untested (apart from the doctests).

  Thanks Mark Dickinson
........
  r58295 | facundo.batista | 2007-10-02 11:21:18 -0700 (Tue, 02 Oct 2007) | 4 lines


  Added a class to store the digits of log(10), so that they can be made
  available when necessary without recomputing.  Thanks Mark Dickinson
........
  r58299 | mark.summerfield | 2007-10-03 01:53:21 -0700 (Wed, 03 Oct 2007) | 4 lines

  Added note in footnote about string comparisons about
  unicodedata.normalize().
........
  r58304 | raymond.hettinger | 2007-10-03 14:18:11 -0700 (Wed, 03 Oct 2007) | 1 line

  enumerate() is no longer bounded to using sequences shorter than LONG_MAX.  The possibility of overflow was sending some newsgroup posters into a tizzy.
........
  r58305 | raymond.hettinger | 2007-10-03 17:20:27 -0700 (Wed, 03 Oct 2007) | 1 line

  itertools.count() no longer limited to sys.maxint.
........
  r58306 | kurt.kaiser | 2007-10-03 18:49:54 -0700 (Wed, 03 Oct 2007) | 3 lines

  Assume that the user knows when he wants to end the line; don't insert
  something he didn't select or complete.
........
  r58307 | kurt.kaiser | 2007-10-03 19:07:50 -0700 (Wed, 03 Oct 2007) | 2 lines

  Remove unused theme that was causing a fault in p3k.
........
  r58308 | kurt.kaiser | 2007-10-03 19:09:17 -0700 (Wed, 03 Oct 2007) | 2 lines

  Clean up EditorWindow close.
........
  r58309 | kurt.kaiser | 2007-10-03 19:53:07 -0700 (Wed, 03 Oct 2007) | 7 lines

  textView cleanup. Patch 1718043 Tal Einat.

  M    idlelib/EditorWindow.py
  M    idlelib/aboutDialog.py
  M    idlelib/textView.py
  M    idlelib/NEWS.txt
........
  r58310 | kurt.kaiser | 2007-10-03 20:11:12 -0700 (Wed, 03 Oct 2007) | 3 lines

  configDialog cleanup. Patch 1730217 Tal Einat.
........
  r58311 | neal.norwitz | 2007-10-03 23:00:48 -0700 (Wed, 03 Oct 2007) | 4 lines

  Coverity #151: Remove deadcode.

  All this code already exists above starting at line 653.
........
  r58325 | fred.drake | 2007-10-04 19:46:12 -0700 (Thu, 04 Oct 2007) | 1 line

  wrap lines to <80 characters before fixing errors
........
  r58326 | raymond.hettinger | 2007-10-04 19:47:07 -0700 (Thu, 04 Oct 2007) | 6 lines

  Add __asdict__() to NamedTuple and refine the docs.
  Add maxlen support to deque() and fixup docs.
  Partially fix __reduce__().  The None as a third arg was no longer supported.
  Still needs work on __reduce__() to handle recursive inputs.
........
  r58327 | fred.drake | 2007-10-04 19:48:32 -0700 (Thu, 04 Oct 2007) | 3 lines

  move descriptions of ac_(in|out)_buffer_size to the right place
  http://bugs.python.org/issue1053
........
  r58329 | neal.norwitz | 2007-10-04 20:39:17 -0700 (Thu, 04 Oct 2007) | 3 lines

  dict could be NULL, so we need to XDECREF.
  Fix a compiler warning about passing a PyTypeObject* instead of PyObject*.
........
  r58330 | neal.norwitz | 2007-10-04 20:41:19 -0700 (Thu, 04 Oct 2007) | 2 lines

  Fix Coverity #158: Check the correct variable.
........
  r58332 | neal.norwitz | 2007-10-04 22:01:38 -0700 (Thu, 04 Oct 2007) | 7 lines

  Fix Coverity #159.

  This code was broken if save() returned a negative number since i contained
  a boolean value and then we compared i < 0 which should never be true.

  Will backport (assuming it's necessary)
........
  r58334 | neal.norwitz | 2007-10-04 22:29:17 -0700 (Thu, 04 Oct 2007) | 1 line

  Add a note about fixing some more warnings found by Coverity.
........
  r58338 | raymond.hettinger | 2007-10-05 12:07:31 -0700 (Fri, 05 Oct 2007) | 1 line

  Restore BEGIN/END THREADS macros which were squashed in the previous checkin
........
  r58343 | gregory.p.smith | 2007-10-06 00:48:10 -0700 (Sat, 06 Oct 2007) | 3 lines

  Stab in the dark attempt to fix the test_bsddb3 failure on sparc and S-390
  ubuntu buildbots.
........
  r58344 | gregory.p.smith | 2007-10-06 00:51:59 -0700 (Sat, 06 Oct 2007) | 2 lines

  Allows BerkeleyDB 4.6.x >= 4.6.21 for the bsddb module.
........
  r58348 | gregory.p.smith | 2007-10-06 08:47:37 -0700 (Sat, 06 Oct 2007) | 3 lines

  Use the host the author likely meant in the first place.  pop.gmail.com is
  reliable.  gmail.org is someones personal domain.
........
  r58351 | neal.norwitz | 2007-10-06 12:16:28 -0700 (Sat, 06 Oct 2007) | 3 lines

  Ensure that this test will pass even if another test left an unwritable TESTFN.
  Also use the safe unlink in test_support instead of rolling our own here.
........
  r58368 | georg.brandl | 2007-10-08 00:50:24 -0700 (Mon, 08 Oct 2007) | 3 lines

  #1123: fix the docs for the str.split(None, sep) case.
  Also expand a few other methods' docs, which had more info in the deprecated string module docs.
........
  r58369 | georg.brandl | 2007-10-08 01:06:05 -0700 (Mon, 08 Oct 2007) | 2 lines

  Update docstring of sched, also remove an unused assignment.
........
  r58370 | raymond.hettinger | 2007-10-08 02:14:28 -0700 (Mon, 08 Oct 2007) | 5 lines

  Add comments to NamedTuple code.
  Let the field spec be either a string or a non-string sequence (suggested by Martin Blais with use cases).
  Improve the error message in the case of a SyntaxError (caused by a duplicate field name).
........
  r58371 | raymond.hettinger | 2007-10-08 02:56:29 -0700 (Mon, 08 Oct 2007) | 1 line

  Missed a line in the docs
........
  r58372 | raymond.hettinger | 2007-10-08 03:11:51 -0700 (Mon, 08 Oct 2007) | 1 line

  Better variable names
........
  r58376 | georg.brandl | 2007-10-08 07:12:47 -0700 (Mon, 08 Oct 2007) | 3 lines

  #1199: docs for tp_as_{number,sequence,mapping}, by Amaury Forgeot d'Arc.
  No need to merge this to py3k!
........
  r58380 | raymond.hettinger | 2007-10-08 14:26:58 -0700 (Mon, 08 Oct 2007) | 1 line

  Eliminate camelcase function name
........
  r58381 | andrew.kuchling | 2007-10-08 16:23:03 -0700 (Mon, 08 Oct 2007) | 1 line

  Eliminate camelcase function name
........
  r58382 | raymond.hettinger | 2007-10-08 18:36:23 -0700 (Mon, 08 Oct 2007) | 1 line

  Make the error messages more specific
........
  r58384 | gregory.p.smith | 2007-10-08 23:02:21 -0700 (Mon, 08 Oct 2007) | 10 lines

  Splits Modules/_bsddb.c up into bsddb.h and _bsddb.c and adds a C API
  object available as bsddb.db.api.  This is based on the patch submitted
  by Duncan Grisby here:
    http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
  See this thread for additional info:
    http://sourceforge.net/mailarchive/forum.php?thread_name=E1GAVDK-0002rk-Iw%40apasphere.com&forum_name=pybsddb-users

  It also cleans up the code a little by removing some ifdef/endifs for
  python prior to 2.1 and for unsupported Berkeley DB <= 3.2.
........
  r58385 | gregory.p.smith | 2007-10-08 23:50:43 -0700 (Mon, 08 Oct 2007) | 5 lines

  Fix a double free when positioning a database cursor to a non-existant
  string key (and probably a few other situations with string keys).
  This was reported with a patch as pybsddb sourceforge bug 1708868 by
  jjjhhhlll at gmail.
........
  r58386 | gregory.p.smith | 2007-10-09 00:19:11 -0700 (Tue, 09 Oct 2007) | 3 lines

  Use the highest cPickle protocol in bsddb.dbshelve.  This comes from
  sourceforge pybsddb patch 1551443 by w_barnes.
........
  r58394 | gregory.p.smith | 2007-10-09 11:26:02 -0700 (Tue, 09 Oct 2007) | 2 lines

  remove another sleepycat reference
........
  r58396 | kurt.kaiser | 2007-10-09 12:31:30 -0700 (Tue, 09 Oct 2007) | 3 lines

  Allow interrupt only when executing user code in subprocess
  Patch 1225 Tal Einat modified from IDLE-Spoon.
........
  r58399 | brett.cannon | 2007-10-09 17:07:50 -0700 (Tue, 09 Oct 2007) | 5 lines

  Remove file-level typedefs that were inconsistently used throughout the file.
  Just move over to the public API names.

  Closes issue1238.
........
  r58401 | raymond.hettinger | 2007-10-09 17:26:46 -0700 (Tue, 09 Oct 2007) | 1 line

  Accept Jim Jewett's api suggestion to use None instead of -1 to indicate unbounded deques.
........
  r58403 | kurt.kaiser | 2007-10-09 17:55:40 -0700 (Tue, 09 Oct 2007) | 2 lines

  Allow cursor color change w/o restart. Patch 1725576 Tal Einat.
........
  r58404 | kurt.kaiser | 2007-10-09 18:06:47 -0700 (Tue, 09 Oct 2007) | 2 lines

  show paste if > 80 columns.  Patch 1659326 Tal Einat.
........
  r58415 | thomas.heller | 2007-10-11 12:51:32 -0700 (Thu, 11 Oct 2007) | 5 lines

  On OS X, use os.uname() instead of gestalt.sysv(...) to get the
  operating system version.  This allows to use ctypes when Python
  was configured with --disable-toolbox-glue.
........
  r58419 | neal.norwitz | 2007-10-11 20:01:01 -0700 (Thu, 11 Oct 2007) | 1 line

  Get rid of warning about not being able to create an existing directory.
........
  r58420 | neal.norwitz | 2007-10-11 20:01:30 -0700 (Thu, 11 Oct 2007) | 1 line

  Get rid of warnings on a bunch of platforms by using a proper prototype.
........
  r58421 | neal.norwitz | 2007-10-11 20:01:54 -0700 (Thu, 11 Oct 2007) | 4 lines

  Get rid of compiler warning about retval being used (returned) without
  being initialized.  (gcc warning and Coverity 202)
........
  r58422 | neal.norwitz | 2007-10-11 20:03:23 -0700 (Thu, 11 Oct 2007) | 1 line

  Fix Coverity 168:  Close the file before returning (exiting).
........
  r58423 | neal.norwitz | 2007-10-11 20:04:18 -0700 (Thu, 11 Oct 2007) | 4 lines

  Fix Coverity 180:  Don't overallocate.  We don't need structs, but pointers.
  Also fix a memory leak.
........
  r58424 | neal.norwitz | 2007-10-11 20:05:19 -0700 (Thu, 11 Oct 2007) | 5 lines

  Fix Coverity 185-186:  If the passed in FILE is NULL, uninitialized memory
  would be accessed.

  Will backport.
........
  r58425 | neal.norwitz | 2007-10-11 20:52:34 -0700 (Thu, 11 Oct 2007) | 1 line

  Get this module to compile with bsddb versions prior to 4.3
........
  r58430 | martin.v.loewis | 2007-10-12 01:56:52 -0700 (Fri, 12 Oct 2007) | 3 lines

  Bug #1216: Restore support for Visual Studio 2002.
  Will backport to 2.5.
........
  r58433 | raymond.hettinger | 2007-10-12 10:53:11 -0700 (Fri, 12 Oct 2007) | 1 line

  Fix test of count.__repr__() to ignore the 'L' if the count is a long
........
  r58434 | gregory.p.smith | 2007-10-12 11:44:06 -0700 (Fri, 12 Oct 2007) | 4 lines

  Fixes http://bugs.python.org/issue1233 - bsddb.dbshelve.DBShelf.append
  was useless due to inverted logic.  Also adds a test case for RECNO dbs
  to test_dbshelve.
........
  r58445 | georg.brandl | 2007-10-13 06:20:03 -0700 (Sat, 13 Oct 2007) | 2 lines

  Fix email example.
........
  r58450 | gregory.p.smith | 2007-10-13 16:02:05 -0700 (Sat, 13 Oct 2007) | 2 lines

  Fix an uncollectable reference leak in bsddb.db.DBShelf.append
........
  r58453 | neal.norwitz | 2007-10-13 17:18:40 -0700 (Sat, 13 Oct 2007) | 8 lines

  Let the O/S supply a port if none of the default ports can be used.
  This should make the tests more robust at the expense of allowing
  tests to be sloppier by not requiring them to cleanup after themselves.
  (It will legitamitely help when running two test suites simultaneously
  or if another process is already using one of the predefined ports.)

  Also simplifies (slightLy) the exception handling elsewhere.
........
  r58459 | neal.norwitz | 2007-10-14 11:30:21 -0700 (Sun, 14 Oct 2007) | 2 lines

  Don't raise a string exception, they don't work anymore.
........
  r58460 | neal.norwitz | 2007-10-14 11:40:37 -0700 (Sun, 14 Oct 2007) | 1 line

  Use unittest for assertions
........
  r58468 | armin.rigo | 2007-10-15 00:48:35 -0700 (Mon, 15 Oct 2007) | 2 lines

  test_bigbits was not testing what it seemed to.
........
  r58471 | guido.van.rossum | 2007-10-15 08:54:11 -0700 (Mon, 15 Oct 2007) | 3 lines

  Change a PyErr_Print() into a PyErr_Clear(),
  per discussion in issue 1031213.
........
  r58500 | raymond.hettinger | 2007-10-16 12:18:30 -0700 (Tue, 16 Oct 2007) | 1 line

  Improve error messages
........
  r58506 | raymond.hettinger | 2007-10-16 14:28:32 -0700 (Tue, 16 Oct 2007) | 1 line

  More docs, error messages, and tests
........
  r58507 | andrew.kuchling | 2007-10-16 15:58:03 -0700 (Tue, 16 Oct 2007) | 1 line

  Add items
........
  r58508 | brett.cannon | 2007-10-16 16:24:06 -0700 (Tue, 16 Oct 2007) | 3 lines

  Remove ``:const:`` notation on None in parameter list.  Since the markup is not
  rendered for parameters it just showed up as ``:const:`None` `` in the output.
........
  r58509 | brett.cannon | 2007-10-16 16:26:45 -0700 (Tue, 16 Oct 2007) | 3 lines

  Re-order some functions whose parameters differ between PyObject and const char
  * so that they are next to each other.
........
  r58522 | armin.rigo | 2007-10-17 11:46:37 -0700 (Wed, 17 Oct 2007) | 5 lines

  Fix the overflow checking of list_repeat.
  Introduce overflow checking into list_inplace_repeat.

  Backport candidate, possibly.
........
  r58530 | facundo.batista | 2007-10-17 20:16:03 -0700 (Wed, 17 Oct 2007) | 7 lines


  Issue #1580738.  When HTTPConnection reads the whole stream with read(),
  it closes itself.  When the stream is read in several calls to read(n),
  it should behave in the same way if HTTPConnection knows where the end
  of the stream is (through self.length).  Added a test case for this
  behaviour.
........
  r58531 | facundo.batista | 2007-10-17 20:44:48 -0700 (Wed, 17 Oct 2007) | 3 lines


  Issue 1289, just a typo.
........
  r58532 | gregory.p.smith | 2007-10-18 00:56:54 -0700 (Thu, 18 Oct 2007) | 4 lines

  cleanup test_dbtables to use mkdtemp.  cleanup dbtables to pass txn as a
  keyword argument whenever possible to avoid bugs and confusion.  (dbtables.py
  line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
........
  r58533 | gregory.p.smith | 2007-10-18 01:34:20 -0700 (Thu, 18 Oct 2007) | 4 lines

  Fix a weird bug in dbtables: if it chose a random rowid string that contained
  NULL bytes it would cause the database all sorts of problems in the future
  leading to very strange random failures and corrupt dbtables.bsdTableDb dbs.
........
  r58534 | gregory.p.smith | 2007-10-18 09:32:02 -0700 (Thu, 18 Oct 2007) | 3 lines

  A cleaner fix than the one committed last night.  Generate random rowids that
  do not contain null bytes.
........
  r58537 | gregory.p.smith | 2007-10-18 10:17:57 -0700 (Thu, 18 Oct 2007) | 2 lines

  mention bsddb fixes.
........
  r58538 | raymond.hettinger | 2007-10-18 14:13:06 -0700 (Thu, 18 Oct 2007) | 1 line

  Remove useless warning
........
  r58539 | gregory.p.smith | 2007-10-19 00:31:20 -0700 (Fri, 19 Oct 2007) | 2 lines

  squelch the warning that this test is supposed to trigger.
........
  r58542 | georg.brandl | 2007-10-19 05:32:39 -0700 (Fri, 19 Oct 2007) | 2 lines

  Clarify wording for apply().
........
  r58544 | mark.summerfield | 2007-10-19 05:48:17 -0700 (Fri, 19 Oct 2007) | 3 lines

  Added a cross-ref to each other.
........
  r58545 | georg.brandl | 2007-10-19 10:38:49 -0700 (Fri, 19 Oct 2007) | 2 lines

  #1284: "S" means "seen", not unread.
........
  r58548 | thomas.heller | 2007-10-19 11:11:41 -0700 (Fri, 19 Oct 2007) | 4 lines

  Fix ctypes on 32-bit systems when Python is configured --with-system-ffi.
  See also https://bugs.launchpad.net/bugs/72505.

  Ported from release25-maint branch.
........
  r58550 | facundo.batista | 2007-10-19 12:25:57 -0700 (Fri, 19 Oct 2007) | 8 lines


  The constructor from tuple was way too permissive: it allowed bad
  coefficient numbers, floats in the sign, and other details that
  generated directly the wrong number in the best case, or triggered
  misfunctionality in the alorithms.

  Test cases added for these issues. Thanks Mark Dickinson.
........
  r58559 | georg.brandl | 2007-10-20 06:22:53 -0700 (Sat, 20 Oct 2007) | 2 lines

  Fix code being interpreted as a target.
........
  r58561 | georg.brandl | 2007-10-20 06:36:24 -0700 (Sat, 20 Oct 2007) | 2 lines

  Document new "cmdoption" directive.
........
  r58562 | georg.brandl | 2007-10-20 08:21:22 -0700 (Sat, 20 Oct 2007) | 2 lines

  Make a path more Unix-standardy.
........
  r58564 | georg.brandl | 2007-10-20 10:51:39 -0700 (Sat, 20 Oct 2007) | 2 lines

  Document new directive "envvar".
........
  r58567 | georg.brandl | 2007-10-20 11:08:14 -0700 (Sat, 20 Oct 2007) | 6 lines

  * Add new toplevel chapter, "Using Python." (how to install,
    configure and setup python on different platforms -- at least
    in theory.)
  * Move the Python on Mac docs in that chapter.
  * Add a new chapter about the command line invocation, by stargaming.
........
  r58568 | georg.brandl | 2007-10-20 11:33:20 -0700 (Sat, 20 Oct 2007) | 2 lines

  Change title, for now.
........
  r58569 | georg.brandl | 2007-10-20 11:39:25 -0700 (Sat, 20 Oct 2007) | 2 lines

  Add entry to ACKS.
........
  r58570 | georg.brandl | 2007-10-20 12:05:45 -0700 (Sat, 20 Oct 2007) | 2 lines

  Clarify -E docs.
........
  r58571 | georg.brandl | 2007-10-20 12:08:36 -0700 (Sat, 20 Oct 2007) | 2 lines

  Even more clarification.
........
  r58572 | andrew.kuchling | 2007-10-20 12:25:37 -0700 (Sat, 20 Oct 2007) | 1 line

  Fix protocol name
........
  r58573 | andrew.kuchling | 2007-10-20 12:35:18 -0700 (Sat, 20 Oct 2007) | 1 line

  Various items
........
  r58574 | andrew.kuchling | 2007-10-20 12:39:35 -0700 (Sat, 20 Oct 2007) | 1 line

  Use correct header line
........
  r58576 | armin.rigo | 2007-10-21 02:14:15 -0700 (Sun, 21 Oct 2007) | 3 lines

  Add a crasher for the long-standing issue with closing a file
  while another thread uses it.
........
  r58577 | georg.brandl | 2007-10-21 03:01:56 -0700 (Sun, 21 Oct 2007) | 2 lines

  Remove duplicate crasher.
........
  r58578 | georg.brandl | 2007-10-21 03:24:20 -0700 (Sun, 21 Oct 2007) | 2 lines

  Unify "byte code" to "bytecode". Also sprinkle :term: markup for it.
........
  r58579 | georg.brandl | 2007-10-21 03:32:54 -0700 (Sun, 21 Oct 2007) | 2 lines

  Add markup to new function descriptions.
........
  r58580 | georg.brandl | 2007-10-21 03:45:46 -0700 (Sun, 21 Oct 2007) | 2 lines

  Add :term:s for descriptors.
........
  r58581 | georg.brandl | 2007-10-21 03:46:24 -0700 (Sun, 21 Oct 2007) | 2 lines

  Unify "file-descriptor" to "file descriptor".
........
  r58582 | georg.brandl | 2007-10-21 03:52:38 -0700 (Sun, 21 Oct 2007) | 2 lines

  Add :term: for generators.
........
  r58583 | georg.brandl | 2007-10-21 05:10:28 -0700 (Sun, 21 Oct 2007) | 2 lines

  Add :term:s for iterator.
........
  r58584 | georg.brandl | 2007-10-21 05:15:05 -0700 (Sun, 21 Oct 2007) | 2 lines

  Add :term:s for "new-style class".
........
  r58588 | neal.norwitz | 2007-10-21 21:47:54 -0700 (Sun, 21 Oct 2007) | 1 line

  Add Chris Monson so he can edit PEPs.
........
  r58594 | guido.van.rossum | 2007-10-22 09:27:19 -0700 (Mon, 22 Oct 2007) | 4 lines

  Issue #1307, patch by Derek Shockey.
  When "MAIL" is received without args, an exception happens instead of
  sending a 501 syntax error response.
........
  r58598 | travis.oliphant | 2007-10-22 19:40:56 -0700 (Mon, 22 Oct 2007) | 1 line

  Add phuang patch from Issue 708374 which adds offset parameter to mmap module.
........
  r58601 | neal.norwitz | 2007-10-22 22:44:27 -0700 (Mon, 22 Oct 2007) | 2 lines

  Bug #1313, fix typo (wrong variable name) in example.
........
  r58609 | georg.brandl | 2007-10-23 11:21:35 -0700 (Tue, 23 Oct 2007) | 2 lines

  Update Pygments version from externals.
........
  r58618 | guido.van.rossum | 2007-10-23 12:25:41 -0700 (Tue, 23 Oct 2007) | 3 lines

  Issue 1307 by Derek Shockey, fox the same bug for RCPT.
  Neal: please backport!
........
  r58620 | raymond.hettinger | 2007-10-23 13:37:41 -0700 (Tue, 23 Oct 2007) | 1 line

  Shorter name for namedtuple()
........
  r58621 | andrew.kuchling | 2007-10-23 13:55:47 -0700 (Tue, 23 Oct 2007) | 1 line

  Update name
........
  r58622 | raymond.hettinger | 2007-10-23 14:23:07 -0700 (Tue, 23 Oct 2007) | 1 line

  Fixup news entry
........
  r58623 | raymond.hettinger | 2007-10-23 18:28:33 -0700 (Tue, 23 Oct 2007) | 1 line

  Optimize sum() for integer and float inputs.
........
  r58624 | raymond.hettinger | 2007-10-23 19:05:51 -0700 (Tue, 23 Oct 2007) | 1 line

  Fixup error return and add support for intermixed ints and floats/
........
  r58628 | vinay.sajip | 2007-10-24 03:47:06 -0700 (Wed, 24 Oct 2007) | 1 line

  Bug #1321: Fixed logic error in TimedRotatingFileHandler.__init__()
........
  r58641 | facundo.batista | 2007-10-24 12:11:08 -0700 (Wed, 24 Oct 2007) | 4 lines


  Issue 1290.  CharacterData.__repr__ was constructing a string
  in response that keeped having a non-ascii character.
........
  r58643 | thomas.heller | 2007-10-24 12:50:45 -0700 (Wed, 24 Oct 2007) | 1 line

  Added unittest for calling a function with paramflags (backport from py3k branch).
........
  r58645 | matthias.klose | 2007-10-24 13:00:44 -0700 (Wed, 24 Oct 2007) | 2 lines

  - Build using system ffi library on arm*-linux*.
........
  r58651 | georg.brandl | 2007-10-24 14:40:38 -0700 (Wed, 24 Oct 2007) | 2 lines

  Bug #1287: make os.environ.pop() work as expected.
........
  r58652 | raymond.hettinger | 2007-10-24 19:26:58 -0700 (Wed, 24 Oct 2007) | 1 line

  Missing DECREFs
........
  r58653 | matthias.klose | 2007-10-24 23:37:24 -0700 (Wed, 24 Oct 2007) | 2 lines

  - Build using system ffi library on arm*-linux*, pass --with-system-ffi to CONFIG_ARGS
........
  r58655 | thomas.heller | 2007-10-25 12:47:32 -0700 (Thu, 25 Oct 2007) | 2 lines

  ffi_type_longdouble may be already #defined.
  See issue 1324.
........
  r58656 | kurt.kaiser | 2007-10-25 15:43:45 -0700 (Thu, 25 Oct 2007) | 3 lines

  Correct an ancient bug in an unused path by removing that path: register() is
  now idempotent.
........
  r58660 | kurt.kaiser | 2007-10-25 17:10:09 -0700 (Thu, 25 Oct 2007) | 4 lines

  1. Add comments to provide top-level documentation.
  2. Refactor to use more descriptive names.
  3. Enhance tests in main().
........
  r58675 | georg.brandl | 2007-10-26 11:30:41 -0700 (Fri, 26 Oct 2007) | 2 lines

  Fix new pop() method on os.environ on ignorecase-platforms.
........
  r58696 | neal.norwitz | 2007-10-27 15:32:21 -0700 (Sat, 27 Oct 2007) | 1 line

  Update URL for Pygments.  0.8.1 is no longer available
........
  r58697 | hyeshik.chang | 2007-10-28 04:19:02 -0700 (Sun, 28 Oct 2007) | 3 lines

  - Add support for FreeBSD 8 which is recently forked from FreeBSD 7.
  - Regenerate IN module for most recent maintenance tree of FreeBSD 6 and 7.
........
  r58698 | hyeshik.chang | 2007-10-28 05:38:09 -0700 (Sun, 28 Oct 2007) | 2 lines

  Enable platform-specific tweaks for FreeBSD 8 (exactly same to FreeBSD 7's yet)
........
  r58700 | kurt.kaiser | 2007-10-28 12:03:59 -0700 (Sun, 28 Oct 2007) | 2 lines

  Add confirmation dialog before printing.  Patch 1717170 Tal Einat.
........
  r58706 | guido.van.rossum | 2007-10-29 13:52:45 -0700 (Mon, 29 Oct 2007) | 3 lines

  Patch 1353 by Jacob Winther.
  Add mp4 mapping to mimetypes.py.
........
  r58709 | guido.van.rossum | 2007-10-29 15:15:05 -0700 (Mon, 29 Oct 2007) | 6 lines

  Backport fixes for the code that decodes octal escapes (and for PyString
  also hex escapes) -- this was reaching beyond the end of the input string
  buffer, even though it is not supposed to be \0-terminated.
  This has no visible effect but is clearly the correct thing to do.
  (In 3.0 it had a visible effect after removing ob_sstate from PyString.)
........
  r58710 | kurt.kaiser | 2007-10-29 19:38:54 -0700 (Mon, 29 Oct 2007) | 7 lines

  check in Tal Einat's update to tabpage.py
  Patch 1612746

  M    configDialog.py
  M    NEWS.txt
  AM   tabbedpages.py
........
  r58715 | georg.brandl | 2007-10-30 10:51:18 -0700 (Tue, 30 Oct 2007) | 2 lines

  Use correct markup.
........
  r58716 | georg.brandl | 2007-10-30 10:57:12 -0700 (Tue, 30 Oct 2007) | 2 lines

  Make example about hiding None return values at the prompt clearer.
........
  r58728 | neal.norwitz | 2007-10-30 23:33:20 -0700 (Tue, 30 Oct 2007) | 1 line

  Fix some compiler warnings for signed comparisons on Unix and Windows.
........
  r58731 | martin.v.loewis | 2007-10-31 10:19:33 -0700 (Wed, 31 Oct 2007) | 2 lines

  Adding Christian Heimes.
........
  r58737 | raymond.hettinger | 2007-10-31 14:57:58 -0700 (Wed, 31 Oct 2007) | 1 line

  Clarify the reasons why pickle is almost always better than marshal
........
  r58739 | raymond.hettinger | 2007-10-31 15:15:49 -0700 (Wed, 31 Oct 2007) | 1 line

  Sets are marshalable.
........
parent 8ce8a784
...@@ -104,6 +104,7 @@ docs@python.org), and we'll be glad to correct the problem. ...@@ -104,6 +104,7 @@ docs@python.org), and we'll be glad to correct the problem.
* Detlef Lannert * Detlef Lannert
* Piers Lauder * Piers Lauder
* Glyph Lefkowitz * Glyph Lefkowitz
* Robert Lehmann
* Marc-André Lemburg * Marc-André Lemburg
* Ulf A. Lindgren * Ulf A. Lindgren
* Everett Lipman * Everett Lipman
......
...@@ -72,7 +72,7 @@ or by installing it from http://docutils.sf.net/. ...@@ -72,7 +72,7 @@ or by installing it from http://docutils.sf.net/.
You can optionally also install Pygments, either as a checkout via :: You can optionally also install Pygments, either as a checkout via ::
svn co http://svn.python.org/projects/external/Pygments-0.8.1/pygments tools/pygments svn co http://svn.python.org/projects/external/Pygments-0.9/pygments tools/pygments
or from PyPI at http://pypi.python.org/pypi/Pygments. or from PyPI at http://pypi.python.org/pypi/Pygments.
......
...@@ -31,21 +31,14 @@ Object Protocol ...@@ -31,21 +31,14 @@ Object Protocol
instead of the :func:`repr`. instead of the :func:`repr`.
.. cfunction:: int PyObject_HasAttrString(PyObject *o, const char *attr_name) .. cfunction:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name)
Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This
is equivalent to the Python expression ``hasattr(o, attr_name)``. This function is equivalent to the Python expression ``hasattr(o, attr_name)``. This function
always succeeds. always succeeds.
.. cfunction:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name) .. cfunction:: int PyObject_HasAttrString(PyObject *o, const char *attr_name)
Retrieve an attribute named *attr_name* from object *o*. Returns the attribute
value on success, or *NULL* on failure. This is the equivalent of the Python
expression ``o.attr_name``.
.. cfunction:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name)
Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This
is equivalent to the Python expression ``hasattr(o, attr_name)``. This function is equivalent to the Python expression ``hasattr(o, attr_name)``. This function
...@@ -59,27 +52,34 @@ Object Protocol ...@@ -59,27 +52,34 @@ Object Protocol
expression ``o.attr_name``. expression ``o.attr_name``.
.. cfunction:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v) .. cfunction:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name)
Retrieve an attribute named *attr_name* from object *o*. Returns the attribute
value on success, or *NULL* on failure. This is the equivalent of the Python
expression ``o.attr_name``.
.. cfunction:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v)
Set the value of the attribute named *attr_name*, for object *o*, to the value Set the value of the attribute named *attr_name*, for object *o*, to the value
*v*. Returns ``-1`` on failure. This is the equivalent of the Python statement *v*. Returns ``-1`` on failure. This is the equivalent of the Python statement
``o.attr_name = v``. ``o.attr_name = v``.
.. cfunction:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v) .. cfunction:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v)
Set the value of the attribute named *attr_name*, for object *o*, to the value Set the value of the attribute named *attr_name*, for object *o*, to the value
*v*. Returns ``-1`` on failure. This is the equivalent of the Python statement *v*. Returns ``-1`` on failure. This is the equivalent of the Python statement
``o.attr_name = v``. ``o.attr_name = v``.
.. cfunction:: int PyObject_DelAttrString(PyObject *o, const char *attr_name) .. cfunction:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name)
Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure. Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure.
This is the equivalent of the Python statement: ``del o.attr_name``. This is the equivalent of the Python statement ``del o.attr_name``.
.. cfunction:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name) .. cfunction:: int PyObject_DelAttrString(PyObject *o, const char *attr_name)
Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure. Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure.
This is the equivalent of the Python statement ``del o.attr_name``. This is the equivalent of the Python statement ``del o.attr_name``.
...@@ -327,7 +327,10 @@ is considered sufficient for this determination. ...@@ -327,7 +327,10 @@ is considered sufficient for this determination.
.. cfunction:: int PyObject_AsFileDescriptor(PyObject *o) .. cfunction:: int PyObject_AsFileDescriptor(PyObject *o)
Derives a file-descriptor from a Python object. Derives a file descriptor from a Python object. If the object is an integer or
long integer, its value is returned. If not, the object's :meth:`fileno` method
is called if it exists; the method must return an integer or long integer, which
is returned as the file descriptor value. Returns ``-1`` on failure.
.. cfunction:: PyObject* PyObject_Dir(PyObject *o) .. cfunction:: PyObject* PyObject_Dir(PyObject *o)
......
...@@ -12,12 +12,6 @@ extension modules or embed Python. It is a companion to :ref:`extending-index`, ...@@ -12,12 +12,6 @@ extension modules or embed Python. It is a companion to :ref:`extending-index`,
which describes the general principles of extension writing but does not which describes the general principles of extension writing but does not
document the API functions in detail. document the API functions in detail.
.. warning::
The current version of this document is somewhat incomplete. However, most of
the important functions, types and structures are described.
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
......
...@@ -618,8 +618,8 @@ type objects) *must* have the :attr:`ob_size` field. ...@@ -618,8 +618,8 @@ type objects) *must* have the :attr:`ob_size` field.
objects which implement the mapping protocol. These fields are documented in objects which implement the mapping protocol. These fields are documented in
:ref:`mapping-structs`. :ref:`mapping-structs`.
The :attr:`tp_as_mapping` field is not inherited, but the contained fields are The :attr:`tp_as_mapping` field is not inherited, but the contained fields
inherited individually. are inherited individually.
.. cmember:: hashfunc PyTypeObject.tp_hash .. cmember:: hashfunc PyTypeObject.tp_hash
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
whatsnew/3.0.rst whatsnew/3.0.rst
tutorial/index.rst tutorial/index.rst
using/index.rst
reference/index.rst reference/index.rst
library/index.rst library/index.rst
extending/index.rst extending/index.rst
......
...@@ -1199,7 +1199,7 @@ other utility module. ...@@ -1199,7 +1199,7 @@ other utility module.
If *force* is true, all files are recompiled regardless of timestamps. If *force* is true, all files are recompiled regardless of timestamps.
The source filename encoded in each bytecode file defaults to the filenames The source filename encoded in each :term:`bytecode` file defaults to the filenames
listed in *py_files*; you can modify these with *prefix* and *basedir*. listed in *py_files*; you can modify these with *prefix* and *basedir*.
*prefix* is a string that will be stripped off of each source filename, and *prefix* is a string that will be stripped off of each source filename, and
*base_dir* is a directory name that will be prepended (after *prefix* is *base_dir* is a directory name that will be prepended (after *prefix* is
......
...@@ -311,7 +311,7 @@ will reflect this and now has the form :file:`foo-1.0.win32-py2.0.exe`. You ...@@ -311,7 +311,7 @@ will reflect this and now has the form :file:`foo-1.0.win32-py2.0.exe`. You
have to create a separate installer for every Python version you want to have to create a separate installer for every Python version you want to
support. support.
The installer will try to compile pure modules into bytecode after installation The installer will try to compile pure modules into :term:`bytecode` after installation
on the target system in normal and optimizing mode. If you don't want this to on the target system in normal and optimizing mode. If you don't want this to
happen for some reason, you can run the :command:`bdist_wininst` command with happen for some reason, you can run the :command:`bdist_wininst` command with
the :option:`--no-target-compile` and/or the :option:`--no-target-optimize` the :option:`--no-target-compile` and/or the :option:`--no-target-optimize`
......
...@@ -210,7 +210,20 @@ The directives are: ...@@ -210,7 +210,20 @@ The directives are:
.. describe:: opcode .. describe:: opcode
Describes a Python bytecode instruction. Describes a Python :term:`bytecode` instruction.
.. describe:: cmdoption
Describes a command line option or switch. Option argument names should be
enclosed in angle brackets. Example::
.. cmdoption:: -m <module>
Run a module as a script.
.. describe:: envvar
Describes an environment variable that Python uses or defines.
There is also a generic version of these directives: There is also a generic version of these directives:
......
...@@ -1110,7 +1110,7 @@ Note that this list does not place any restrictions on the values of the ...@@ -1110,7 +1110,7 @@ Note that this list does not place any restrictions on the values of the
attributes, when the values are computed, or how relevant data is stored. attributes, when the values are computed, or how relevant data is stored.
When :cfunc:`PyType_Ready` is called, it uses three tables referenced by the When :cfunc:`PyType_Ready` is called, it uses three tables referenced by the
type object to create *descriptors* which are placed in the dictionary of the type object to create :term:`descriptor`\s which are placed in the dictionary of the
type object. Each descriptor controls access to one attribute of the instance type object. Each descriptor controls access to one attribute of the instance
object. Each of the tables is optional; if all three are *NULL*, instances of object. Each of the tables is optional; if all three are *NULL*, instances of
the type will only have attributes that are inherited from their base type, and the type will only have attributes that are inherited from their base type, and
...@@ -1154,7 +1154,7 @@ be read-only or read-write. The structures in the table are defined as:: ...@@ -1154,7 +1154,7 @@ be read-only or read-write. The structures in the table are defined as::
char *doc; char *doc;
} PyMemberDef; } PyMemberDef;
For each entry in the table, a descriptor will be constructed and added to the For each entry in the table, a :term:`descriptor` will be constructed and added to the
type which will be able to extract a value from the instance structure. The type which will be able to extract a value from the instance structure. The
:attr:`type` field should contain one of the type codes defined in the :attr:`type` field should contain one of the type codes defined in the
:file:`structmember.h` header; the value will be used to determine how to :file:`structmember.h` header; the value will be used to determine how to
......
...@@ -20,13 +20,13 @@ Glossary ...@@ -20,13 +20,13 @@ Glossary
Benevolent Dictator For Life, a.k.a. `Guido van Rossum Benevolent Dictator For Life, a.k.a. `Guido van Rossum
<http://www.python.org/~guido/>`_, Python's creator. <http://www.python.org/~guido/>`_, Python's creator.
byte code bytecode
The internal representation of a Python program in the interpreter. The Python source code is compiled into bytecode, the internal representation
byte code is also cached in ``.pyc`` and ``.pyo`` files so that executing of a Python program in the interpreter. The bytecode is also cached in
the same file is faster the second time (recompilation from source to byte ``.pyc`` and ``.pyo`` files so that executing the same file is faster the
code can be avoided). This "intermediate language" is said to run on a second time (recompilation from source to bytecode can be avoided). This
"virtual machine" that calls the subroutines corresponding to each "intermediate language" is said to run on a "virtual machine" that calls
bytecode. the subroutines corresponding to each bytecode.
classic class classic class
One of the two flavors of classes in earlier Python versions. Since One of the two flavors of classes in earlier Python versions. Since
...@@ -47,12 +47,15 @@ Glossary ...@@ -47,12 +47,15 @@ Glossary
descriptor descriptor
An object that defines the methods :meth:`__get__`, :meth:`__set__`, or An object that defines the methods :meth:`__get__`, :meth:`__set__`, or
:meth:`__delete__`. When a class attribute is a descriptor, its special :meth:`__delete__`. When a class attribute is a descriptor, its special
binding behavior is triggered upon attribute lookup. Normally, writing binding behavior is triggered upon attribute lookup. Normally, using
*a.b* looks up the object *b* in the class dictionary for *a*, but if *b* *a.b* to get, set or delete an attribute looks up the object named *b* in
is a descriptor, the defined method gets called. Understanding the class dictionary for *a*, but if *b* is a descriptor, the respective
descriptors is a key to a deep understanding of Python because they are descriptor method gets called. Understanding descriptors is a key to a
the basis for many features including functions, methods, properties, deep understanding of Python because they are the basis for many features
class methods, static methods, and reference to super classes. including functions, methods, properties, class methods, static methods,
and reference to super classes.
For more information about descriptors' methods, see :ref:`descriptors`.
dictionary dictionary
An associative array, where arbitrary keys are mapped to values. The use An associative array, where arbitrary keys are mapped to values. The use
...@@ -209,6 +212,8 @@ Glossary ...@@ -209,6 +212,8 @@ Glossary
with an iterator will just return the same exhausted iterator object used with an iterator will just return the same exhausted iterator object used
in the previous iteration pass, making it appear like an empty container. in the previous iteration pass, making it appear like an empty container.
More information can be found in :ref:`typeiter`.
LBYL LBYL
Look before you leap. This coding style explicitly tests for Look before you leap. This coding style explicitly tests for
pre-conditions before making calls or lookups. This style contrasts with pre-conditions before making calls or lookups. This style contrasts with
...@@ -238,6 +243,8 @@ Glossary ...@@ -238,6 +243,8 @@ Glossary
access, adding thread-safety, tracking object creation, implementing access, adding thread-safety, tracking object creation, implementing
singletons, and many other tasks. singletons, and many other tasks.
More information can be found in :ref:`metaclasses`.
mutable mutable
Mutable objects can change their value but keep their :func:`id`. See Mutable objects can change their value but keep their :func:`id`. See
also :term:`immutable`. also :term:`immutable`.
...@@ -268,6 +275,8 @@ Glossary ...@@ -268,6 +275,8 @@ Glossary
versatile features like :attr:`__slots__`, descriptors, properties, versatile features like :attr:`__slots__`, descriptors, properties,
:meth:`__getattribute__`, class methods, and static methods. :meth:`__getattribute__`, class methods, and static methods.
More information can be found in :ref:`newstyle`.
Python 3000 Python 3000
Nickname for the next major Python version, 3.0 (coined long ago when the Nickname for the next major Python version, 3.0 (coined long ago when the
release of version 3 was something in the distant future.) release of version 3 was something in the distant future.)
......
...@@ -13,8 +13,8 @@ disclaimer.) ...@@ -13,8 +13,8 @@ disclaimer.)
In this document, we'll take a tour of Python's features suitable for In this document, we'll take a tour of Python's features suitable for
implementing programs in a functional style. After an introduction to the implementing programs in a functional style. After an introduction to the
concepts of functional programming, we'll look at language features such as concepts of functional programming, we'll look at language features such as
iterators and generators and relevant library modules such as :mod:`itertools` :term:`iterator`\s and :term:`generator`\s and relevant library modules such as
and :mod:`functools`. :mod:`itertools` and :mod:`functools`.
Introduction Introduction
...@@ -448,8 +448,8 @@ Here's the simplest example of a generator function:: ...@@ -448,8 +448,8 @@ Here's the simplest example of a generator function::
yield i yield i
Any function containing a ``yield`` keyword is a generator function; this is Any function containing a ``yield`` keyword is a generator function; this is
detected by Python's bytecode compiler which compiles the function specially as detected by Python's :term:`bytecode` compiler which compiles the function
a result. specially as a result.
When you call a generator function, it doesn't return a single value; instead it When you call a generator function, it doesn't return a single value; instead it
returns a generator object that supports the iterator protocol. On executing returns a generator object that supports the iterator protocol. On executing
......
...@@ -14,7 +14,6 @@ Currently, the HOWTOs are: ...@@ -14,7 +14,6 @@ Currently, the HOWTOs are:
:maxdepth: 1 :maxdepth: 1
advocacy.rst advocacy.rst
pythonmac.rst
curses.rst curses.rst
doanddont.rst doanddont.rst
functional.rst functional.rst
......
.. _using-on-mac:
***************************
Using Python on a Macintosh
***************************
:Author: Bob Savage <bobsavage@mac.com>
Python on a Macintosh running Mac OS X is in principle very similar to Python on
any other Unix platform, but there are a number of additional features such as
the IDE and the Package Manager that are worth pointing out.
The Mac-specific modules are documented in :ref:`mac-specific-services`.
Python on Mac OS 9 or earlier can be quite different from Python on Unix or
Windows, but is beyond the scope of this manual, as that platform is no longer
supported, starting with Python 2.4. See http://www.cwi.nl/~jack/macpython for
installers for the latest 2.3 release for Mac OS 9 and related documentation.
.. _getting-osx:
Getting and Installing MacPython
================================
Mac OS X 10.4 comes with Python 2.3 pre-installed by Apple. However, you are
encouraged to install the most recent version of Python from the Python website
(http://www.python.org). A "universal binary" build of Python 2.5, which runs
natively on the Mac's new Intel and legacy PPC CPU's, is available there.
What you get after installing is a number of things:
* A :file:`MacPython 2.5` folder in your :file:`Applications` folder. In here
you find IDLE, the development environment that is a standard part of official
Python distributions; PythonLauncher, which handles double-clicking Python
scripts from the Finder; and the "Build Applet" tool, which allows you to
package Python scripts as standalone applications on your system.
* A framework :file:`/Library/Frameworks/Python.framework`, which includes the
Python executable and libraries. The installer adds this location to your shell
path. To uninstall MacPython, you can simply remove these three things. A
symlink to the Python executable is placed in /usr/local/bin/.
The Apple-provided build of Python is installed in
:file:`/System/Library/Frameworks/Python.framework` and :file:`/usr/bin/python`,
respectively. You should never modify or delete these, as they are
Apple-controlled and are used by Apple- or third-party software.
IDLE includes a help menu that allows you to access Python documentation. If you
are completely new to Python you should start reading the tutorial introduction
in that document.
If you are familiar with Python on other Unix platforms you should read the
section on running Python scripts from the Unix shell.
How to run a Python script
--------------------------
Your best way to get started with Python on Mac OS X is through the IDLE
integrated development environment, see section :ref:`ide` and use the Help menu
when the IDE is running.
If you want to run Python scripts from the Terminal window command line or from
the Finder you first need an editor to create your script. Mac OS X comes with a
number of standard Unix command line editors, :program:`vim` and
:program:`emacs` among them. If you want a more Mac-like editor,
:program:`BBEdit` or :program:`TextWrangler` from Bare Bones Software (see
http://www.barebones.com/products/bbedit/index.shtml) are good choices, as is
:program:`TextMate` (see http://macromates.com/). Other editors include
:program:`Gvim` (http://macvim.org) and :program:`Aquamacs`
(http://aquamacs.org).
To run your script from the Terminal window you must make sure that
:file:`/usr/local/bin` is in your shell search path.
To run your script from the Finder you have two options:
* Drag it to :program:`PythonLauncher`
* Select :program:`PythonLauncher` as the default application to open your
script (or any .py script) through the finder Info window and double-click it.
:program:`PythonLauncher` has various preferences to control how your script is
launched. Option-dragging allows you to change these for one invocation, or use
its Preferences menu to change things globally.
.. _osx-gui-scripts:
Running scripts with a GUI
--------------------------
With older versions of Python, there is one Mac OS X quirk that you need to be
aware of: programs that talk to the Aqua window manager (in other words,
anything that has a GUI) need to be run in a special way. Use :program:`pythonw`
instead of :program:`python` to start such scripts.
With Python 2.5, you can use either :program:`python` or :program:`pythonw`.
Configuration
-------------
Python on OS X honors all standard Unix environment variables such as
:envvar:`PYTHONPATH`, but setting these variables for programs started from the
Finder is non-standard as the Finder does not read your :file:`.profile` or
:file:`.cshrc` at startup. You need to create a file :file:`~
/.MacOSX/environment.plist`. See Apple's Technical Document QA1067 for details.
For more information on installation Python packages in MacPython, see section
:ref:`mac-package-manager`.
.. _ide:
The IDE
=======
MacPython ships with the standard IDLE development environment. A good
introduction to using IDLE can be found at http://hkn.eecs.berkeley.edu/
dyoo/python/idle_intro/index.html.
.. _mac-package-manager:
Installing Additional Python Packages
=====================================
There are several methods to install additional Python packages:
* http://pythonmac.org/packages/ contains selected compiled packages for Python
2.5, 2.4, and 2.3.
* Packages can be installed via the standard Python distutils mode (``python
setup.py install``).
* Many packages can also be installed via the :program:`setuptools` extension.
GUI Programming on the Mac
==========================
There are several options for building GUI applications on the Mac with Python.
*PyObjC* is a Python binding to Apple's Objective-C/Cocoa framework, which is
the foundation of most modern Mac development. Information on PyObjC is
available from http://pyobjc.sourceforge.net.
The standard Python GUI toolkit is :mod:`Tkinter`, based on the cross-platform
Tk toolkit (http://www.tcl.tk). An Aqua-native version of Tk is bundled with OS
X by Apple, and the latest version can be downloaded and installed from
http://www.activestate.com; it can also be built from source.
*wxPython* is another popular cross-platform GUI toolkit that runs natively on
Mac OS X. Packages and documentation are available from http://www.wxpython.org.
*PyQt* is another popular cross-platform GUI toolkit that runs natively on Mac
OS X. More information can be found at
http://www.riverbankcomputing.co.uk/pyqt/.
Distributing Python Applications on the Mac
===========================================
The "Build Applet" tool that is placed in the MacPython 2.5 folder is fine for
packaging small Python scripts on your own machine to run as a standard Mac
application. This tool, however, is not robust enough to distribute Python
applications to other users.
The standard tool for deploying standalone Python applications on the Mac is
:program:`py2app`. More information on installing and using py2app can be found
at http://undefined.org/python/#py2app.
Application Scripting
=====================
Python can also be used to script other Mac applications via Apple's Open
Scripting Architecture (OSA); see http://appscript.sourceforge.net. Appscript is
a high-level, user-friendly Apple event bridge that allows you to control
scriptable Mac OS X applications using ordinary Python scripts. Appscript makes
Python a serious alternative to Apple's own *AppleScript* language for
automating your Mac. A related package, *PyOSA*, is an OSA language component
for the Python scripting language, allowing Python code to be executed by any
OSA-enabled application (Script Editor, Mail, iTunes, etc.). PyOSA makes Python
a full peer to AppleScript.
Other Resources
===============
The MacPython mailing list is an excellent support resource for Python users and
developers on the Mac:
http://www.python.org/community/sigs/current/pythonmac-sig/
Another useful resource is the MacPython wiki:
http://wiki.python.org/moin/MacPython
...@@ -354,7 +354,7 @@ listing. ...@@ -354,7 +354,7 @@ listing.
| | returns them as a list. | | | returns them as a list. |
+------------------+-----------------------------------------------+ +------------------+-----------------------------------------------+
| ``finditer()`` | Find all substrings where the RE matches, and | | ``finditer()`` | Find all substrings where the RE matches, and |
| | returns them as an iterator. | | | returns them as an :term:`iterator`. |
+------------------+-----------------------------------------------+ +------------------+-----------------------------------------------+
:meth:`match` and :meth:`search` return ``None`` if no match can be found. If :meth:`match` and :meth:`search` return ``None`` if no match can be found. If
...@@ -460,7 +460,7 @@ Two :class:`RegexObject` methods return all of the matches for a pattern. ...@@ -460,7 +460,7 @@ Two :class:`RegexObject` methods return all of the matches for a pattern.
:meth:`findall` has to create the entire list before it can be returned as the :meth:`findall` has to create the entire list before it can be returned as the
result. The :meth:`finditer` method returns a sequence of :class:`MatchObject` result. The :meth:`finditer` method returns a sequence of :class:`MatchObject`
instances as an iterator. [#]_ :: instances as an :term:`iterator`. [#]_ ::
>>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...') >>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...')
>>> iterator >>> iterator
......
...@@ -53,7 +53,7 @@ Usage: %prog [options] msgfile ...@@ -53,7 +53,7 @@ Usage: %prog [options] msgfile
# email message can't be used to overwrite important files # email message can't be used to overwrite important files
filename = part.get_filename() filename = part.get_filename()
if not filename: if not filename:
ext = mimetypes.guess_extension(part.get_type()) ext = mimetypes.guess_extension(part.get_content_type())
if not ext: if not ext:
# Use a generic bag-of-bits extension # Use a generic bag-of-bits extension
ext = '.bin' ext = '.bin'
......
...@@ -12,7 +12,7 @@ Abstract Syntax Trees ...@@ -12,7 +12,7 @@ Abstract Syntax Trees
The ``_ast`` module helps Python applications to process trees of the Python The ``_ast`` module helps Python applications to process trees of the Python
abstract syntax grammar. The Python compiler currently provides read-only access abstract syntax grammar. The Python compiler currently provides read-only access
to such trees, meaning that applications can only create a tree for a given to such trees, meaning that applications can only create a tree for a given
piece of Python source code; generating byte code from a (potentially modified) piece of Python source code; generating :term:`bytecode` from a (potentially modified)
tree is not supported. The abstract syntax itself might change with each Python tree is not supported. The abstract syntax itself might change with each Python
release; this module helps to find out programmatically what the current grammar release; this module helps to find out programmatically what the current grammar
looks like. looks like.
......
This diff is collapsed.
This diff is collapsed.
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
The :mod:`autoGIL` module provides a function :func:`installAutoGIL` that The :mod:`autoGIL` module provides a function :func:`installAutoGIL` that
automatically locks and unlocks Python's Global Interpreter Lock when running an automatically locks and unlocks Python's :term:`Global Interpreter Lock` when
event loop. running an event loop.
.. exception:: AutoGILError .. exception:: AutoGILError
......
...@@ -238,15 +238,15 @@ utility functions: ...@@ -238,15 +238,15 @@ utility functions:
.. function:: iterencode(iterable, encoding[, errors]) .. function:: iterencode(iterable, encoding[, errors])
Uses an incremental encoder to iteratively encode the input provided by Uses an incremental encoder to iteratively encode the input provided by
*iterable*. This function is a generator. *errors* (as well as any other keyword *iterable*. This function is a :term:`generator`. *errors* (as well as any
argument) is passed through to the incremental encoder. other keyword argument) is passed through to the incremental encoder.
.. function:: iterdecode(iterable, encoding[, errors]) .. function:: iterdecode(iterable, encoding[, errors])
Uses an incremental decoder to iteratively decode the input provided by Uses an incremental decoder to iteratively decode the input provided by
*iterable*. This function is a generator. *errors* (as well as any other keyword *iterable*. This function is a :term:`generator`. *errors* (as well as any
argument) is passed through to the incremental decoder. other keyword argument) is passed through to the incremental decoder.
The module also provides the following constants which are useful for reading The module also provides the following constants which are useful for reading
and writing to platform dependent files: and writing to platform dependent files:
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
This module implements high-performance container datatypes. Currently, This module implements high-performance container datatypes. Currently,
there are two datatypes, :class:`deque` and :class:`defaultdict`, and there are two datatypes, :class:`deque` and :class:`defaultdict`, and
one datatype factory function, :func:`NamedTuple`. Python already one datatype factory function, :func:`named_tuple`. Python already
includes built-in containers, :class:`dict`, :class:`list`, includes built-in containers, :class:`dict`, :class:`list`,
:class:`set`, and :class:`tuple`. In addition, the optional :mod:`bsddb` :class:`set`, and :class:`tuple`. In addition, the optional :mod:`bsddb`
module has a :meth:`bsddb.btopen` method that can be used to create in-memory module has a :meth:`bsddb.btopen` method that can be used to create in-memory
...@@ -75,7 +75,7 @@ particular functionality, for example:: ...@@ -75,7 +75,7 @@ particular functionality, for example::
---------------------- ----------------------
.. class:: deque([iterable]) .. class:: deque([iterable[, maxlen]])
Returns a new deque object initialized left-to-right (using :meth:`append`) with Returns a new deque object initialized left-to-right (using :meth:`append`) with
data from *iterable*. If *iterable* is not specified, the new deque is empty. data from *iterable*. If *iterable* is not specified, the new deque is empty.
...@@ -91,6 +91,17 @@ particular functionality, for example:: ...@@ -91,6 +91,17 @@ particular functionality, for example::
position of the underlying data representation. position of the underlying data representation.
If *maxlen* is not specified or is *None*, deques may grow to an
arbitrary length. Otherwise, the deque is bounded to the specified maximum
length. Once a bounded length deque is full, when new items are added, a
corresponding number of items are discarded from the opposite end. Bounded
length deques provide functionality similar to the ``tail`` filter in
Unix. They are also useful for tracking transactions and other pools of data
where only the most recent activity is of interest.
.. versionchanged:: 2.6
Added *maxlen*
Deque objects support the following methods: Deque objects support the following methods:
.. method:: deque.append(x) .. method:: deque.append(x)
...@@ -205,8 +216,8 @@ Example:: ...@@ -205,8 +216,8 @@ Example::
.. _deque-recipes: .. _deque-recipes:
Recipes :class:`deque` Recipes
^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
This section shows various approaches to working with deques. This section shows various approaches to working with deques.
...@@ -223,42 +234,14 @@ To implement :class:`deque` slicing, use a similar approach applying ...@@ -223,42 +234,14 @@ To implement :class:`deque` slicing, use a similar approach applying
:meth:`rotate` to bring a target element to the left side of the deque. Remove :meth:`rotate` to bring a target element to the left side of the deque. Remove
old entries with :meth:`popleft`, add new entries with :meth:`extend`, and then old entries with :meth:`popleft`, add new entries with :meth:`extend`, and then
reverse the rotation. reverse the rotation.
With minor variations on that approach, it is easy to implement Forth style With minor variations on that approach, it is easy to implement Forth style
stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``, stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``,
``rot``, and ``roll``. ``rot``, and ``roll``.
A roundrobin task server can be built from a :class:`deque` using
:meth:`popleft` to select the current task and :meth:`append` to add it back to
the tasklist if the input stream is not exhausted::
>>> def roundrobin(*iterables):
... pending = deque(iter(i) for i in iterables)
... while pending:
... task = pending.popleft()
... try:
... yield next(task)
... except StopIteration:
... continue
... pending.append(task)
...
>>> for value in roundrobin('abc', 'd', 'efgh'):
... print(value)
a
d
e
b
f
c
g
h
Multi-pass data reduction algorithms can be succinctly expressed and efficiently Multi-pass data reduction algorithms can be succinctly expressed and efficiently
coded by extracting elements with multiple calls to :meth:`popleft`, applying coded by extracting elements with multiple calls to :meth:`popleft`, applying
the reduction function, and calling :meth:`append` to add the result back to the a reduction function, and calling :meth:`append` to add the result back to the
queue. deque.
For example, building a balanced binary tree of nested lists entails reducing For example, building a balanced binary tree of nested lists entails reducing
two adjacent nodes into one by grouping them in a list:: two adjacent nodes into one by grouping them in a list::
...@@ -273,7 +256,12 @@ two adjacent nodes into one by grouping them in a list:: ...@@ -273,7 +256,12 @@ two adjacent nodes into one by grouping them in a list::
>>> print(maketree('abcdefgh')) >>> print(maketree('abcdefgh'))
[[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]] [[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]]
Bounded length deques provide functionality similar to the ``tail`` filter
in Unix::
def tail(filename, n=10):
'Return the last n lines of a file'
return deque(open(filename), n)
.. _defaultdict-objects: .. _defaultdict-objects:
...@@ -395,14 +383,14 @@ Setting the :attr:`default_factory` to :class:`set` makes the ...@@ -395,14 +383,14 @@ Setting the :attr:`default_factory` to :class:`set` makes the
.. _named-tuple-factory: .. _named-tuple-factory:
:func:`NamedTuple` Factory Function for Tuples with Named Fields :func:`named_tuple` Factory Function for Tuples with Named Fields
---------------------------------------------------------------- -----------------------------------------------------------------
Named tuples assign meaning to each position in a tuple and allow for more readable, Named tuples assign meaning to each position in a tuple and allow for more readable,
self-documenting code. They can be used wherever regular tuples are used, and self-documenting code. They can be used wherever regular tuples are used, and
they add the ability to access fields by name instead of position index. they add the ability to access fields by name instead of position index.
.. function:: NamedTuple(typename, fieldnames, [verbose]) .. function:: named_tuple(typename, fieldnames, [verbose])
Returns a new tuple subclass named *typename*. The new subclass is used to Returns a new tuple subclass named *typename*. The new subclass is used to
create tuple-like objects that have fields accessable by attribute lookup as create tuple-like objects that have fields accessable by attribute lookup as
...@@ -410,17 +398,24 @@ they add the ability to access fields by name instead of position index. ...@@ -410,17 +398,24 @@ they add the ability to access fields by name instead of position index.
helpful docstring (with typename and fieldnames) and a helpful :meth:`__repr__` helpful docstring (with typename and fieldnames) and a helpful :meth:`__repr__`
method which lists the tuple contents in a ``name=value`` format. method which lists the tuple contents in a ``name=value`` format.
The *fieldnames* are specified in a single string with each fieldname separated by The *fieldnames* are a single string with each fieldname separated by whitespace
a space and/or comma. Any valid Python identifier may be used for a fieldname. and/or commas (for example 'x y' or 'x, y'). Alternatively, the *fieldnames*
can be specified as a list of strings (such as ['x', 'y']).
Any valid Python identifier may be used for a fieldname except for names
starting and ending with double underscores. Valid identifiers consist of
letters, digits, and underscores but do not start with a digit and cannot be
a :mod:`keyword` such as *class*, *for*, *return*, *global*, *pass*, *print*,
or *raise*.
If *verbose* is true, will print the class definition. If *verbose* is true, will print the class definition.
*NamedTuple* instances do not have per-instance dictionaries, so they are Named tuple instances do not have per-instance dictionaries, so they are
lightweight and require no more memory than regular tuples. lightweight and require no more memory than regular tuples.
Example:: Example::
>>> Point = NamedTuple('Point', 'x y', True) >>> Point = named_tuple('Point', 'x y', verbose=True)
class Point(tuple): class Point(tuple):
'Point(x, y)' 'Point(x, y)'
__slots__ = () __slots__ = ()
...@@ -429,6 +424,9 @@ Example:: ...@@ -429,6 +424,9 @@ Example::
return tuple.__new__(cls, (x, y)) return tuple.__new__(cls, (x, y))
def __repr__(self): def __repr__(self):
return 'Point(x=%r, y=%r)' % self return 'Point(x=%r, y=%r)' % self
def __asdict__(self):
'Return a new dict mapping field names to their values'
return dict(zip(('x', 'y'), self))
def __replace__(self, field, value): def __replace__(self, field, value):
'Return a new Point object replacing one field with a new value' 'Return a new Point object replacing one field with a new value'
return Point(**dict(zip(('x', 'y'), self) + [(field, value)])) return Point(**dict(zip(('x', 'y'), self) + [(field, value)]))
...@@ -449,23 +447,46 @@ Example:: ...@@ -449,23 +447,46 @@ Example::
Named tuples are especially useful for assigning field names to result tuples returned Named tuples are especially useful for assigning field names to result tuples returned
by the :mod:`csv` or :mod:`sqlite3` modules:: by the :mod:`csv` or :mod:`sqlite3` modules::
EmployeeRecord = named_tuple('EmployeeRecord', 'name, age, title, department, paygrade')
from itertools import starmap from itertools import starmap
import csv import csv
EmployeeRecord = NamedTuple('EmployeeRecord', 'name age title department paygrade')
for record in starmap(EmployeeRecord, csv.reader(open("employees.csv", "rb"))): for record in starmap(EmployeeRecord, csv.reader(open("employees.csv", "rb"))):
print(emp.name, emp.title) print(emp.name, emp.title)
When casting a single record to a *NamedTuple*, use the star-operator [#]_ to unpack import sqlite3
conn = sqlite3.connect('/companydata')
cursor = conn.cursor()
cursor.execute('SELECT name, age, title, department, paygrade FROM employees')
for emp in starmap(EmployeeRecord, cursor.fetchall()):
print emp.name, emp.title
When casting a single record to a named tuple, use the star-operator [#]_ to unpack
the values:: the values::
>>> t = [11, 22] >>> t = [11, 22]
>>> Point(*t) # the star-operator unpacks any iterable object >>> Point(*t) # the star-operator unpacks any iterable object
Point(x=11, y=22) Point(x=11, y=22)
When casting a dictionary to a named tuple, use the double-star-operator::
>>> d = {'x': 11, 'y': 22}
>>> Point(**d)
Point(x=11, y=22)
In addition to the methods inherited from tuples, named tuples support In addition to the methods inherited from tuples, named tuples support
an additonal method and an informational read-only attribute. two additonal methods and a read-only attribute.
.. method:: somenamedtuple.__asdict__()
Return a new dict which maps field names to their corresponding values:
::
>>> p.__asdict__()
{'x': 11, 'y': 22}
.. method:: somenamedtuple.replace(field, value) .. method:: somenamedtuple.__replace__(field, value)
Return a new instance of the named tuple replacing the named *field* with a new *value*: Return a new instance of the named tuple replacing the named *field* with a new *value*:
...@@ -480,20 +501,16 @@ an additonal method and an informational read-only attribute. ...@@ -480,20 +501,16 @@ an additonal method and an informational read-only attribute.
.. attribute:: somenamedtuple.__fields__ .. attribute:: somenamedtuple.__fields__
Return a tuple of strings listing the field names. This is useful for introspection, Return a tuple of strings listing the field names. This is useful for introspection
for converting a named tuple instance to a dictionary, and for combining named tuple and for creating new named tuple types from existing named tuples.
types to create new named tuple types:
:: ::
>>> p.__fields__ # view the field names >>> p.__fields__ # view the field names
('x', 'y') ('x', 'y')
>>> dict(zip(p.__fields__, p)) # convert to a dictionary
{'y': 22, 'x': 11}
>>> Color = NamedTuple('Color', 'red green blue') >>> Color = named_tuple('Color', 'red green blue')
>>> pixel_fields = ' '.join(Point.__fields__ + Color.__fields__) # combine fields >>> Pixel = named_tuple('Pixel', Point.__fields__ + Color.__fields__)
>>> Pixel = NamedTuple('Pixel', pixel_fields)
>>> Pixel(11, 22, 128, 255, 0) >>> Pixel(11, 22, 128, 255, 0)
Pixel(x=11, y=22, red=128, green=255, blue=0)' Pixel(x=11, y=22, red=128, green=255, blue=0)'
......
...@@ -37,9 +37,9 @@ Functions provided: ...@@ -37,9 +37,9 @@ Functions provided:
foo foo
</h1> </h1>
The function being decorated must return a generator-iterator when called. This The function being decorated must return a :term:`generator`-iterator when
iterator must yield exactly one value, which will be bound to the targets in the called. This iterator must yield exactly one value, which will be bound to
:keyword:`with` statement's :keyword:`as` clause, if any. the targets in the :keyword:`with` statement's :keyword:`as` clause, if any.
At the point where the generator yields, the block nested in the :keyword:`with` At the point where the generator yields, the block nested in the :keyword:`with`
statement is executed. The generator is then resumed after the block is exited. statement is executed. The generator is then resumed after the block is exited.
......
...@@ -140,7 +140,7 @@ The following classes are provided: ...@@ -140,7 +140,7 @@ The following classes are provided:
CookieJar and FileCookieJar Objects CookieJar and FileCookieJar Objects
----------------------------------- -----------------------------------
:class:`CookieJar` objects support the iterator protocol for iterating over :class:`CookieJar` objects support the :term:`iterator` protocol for iterating over
contained :class:`Cookie` objects. contained :class:`Cookie` objects.
:class:`CookieJar` has the following methods: :class:`CookieJar` has the following methods:
......
...@@ -60,7 +60,7 @@ The :mod:`csv` module defines the following functions: ...@@ -60,7 +60,7 @@ The :mod:`csv` module defines the following functions:
.. function:: reader(csvfile[, dialect='excel'][, fmtparam]) .. function:: reader(csvfile[, dialect='excel'][, fmtparam])
Return a reader object which will iterate over lines in the given *csvfile*. Return a reader object which will iterate over lines in the given *csvfile*.
*csvfile* can be any object which supports the iterator protocol and returns a *csvfile* can be any object which supports the :term:`iterator` protocol and returns a
string each time its :meth:`next` method is called --- file objects and list string each time its :meth:`next` method is called --- file objects and list
objects are both suitable. If *csvfile* is a file object, it must be opened objects are both suitable. If *csvfile* is a file object, it must be opened
with the 'b' flag on platforms where that makes a difference. An optional with the 'b' flag on platforms where that makes a difference. An optional
...@@ -138,7 +138,7 @@ The :mod:`csv` module defines the following functions: ...@@ -138,7 +138,7 @@ The :mod:`csv` module defines the following functions:
The :mod:`csv` module defines the following classes: The :mod:`csv` module defines the following classes:
.. class:: DictReader(csvfile[, fieldnames=:const:None,[, restkey=:const:None[, restval=None[, dialect='excel'[, *args, **kwds]]]]]) .. class:: DictReader(csvfile[, fieldnames=None[, restkey=None[, restval=None[, dialect='excel'[, *args, **kwds]]]]])
Create an object which operates like a regular reader but maps the information Create an object which operates like a regular reader but maps the information
read into a dict whose keys are given by the optional *fieldnames* parameter. read into a dict whose keys are given by the optional *fieldnames* parameter.
...@@ -436,9 +436,9 @@ it is 8-bit-clean save for some problems with ASCII NUL characters. So you can ...@@ -436,9 +436,9 @@ it is 8-bit-clean save for some problems with ASCII NUL characters. So you can
write functions or classes that handle the encoding and decoding for you as long write functions or classes that handle the encoding and decoding for you as long
as you avoid encodings like UTF-16 that use NULs. UTF-8 is recommended. as you avoid encodings like UTF-16 that use NULs. UTF-8 is recommended.
:func:`unicode_csv_reader` below is a generator that wraps :class:`csv.reader` :func:`unicode_csv_reader` below is a :term:`generator` that wraps :class:`csv.reader`
to handle Unicode CSV data (a list of Unicode strings). :func:`utf_8_encoder` to handle Unicode CSV data (a list of Unicode strings). :func:`utf_8_encoder`
is a generator that encodes the Unicode strings as UTF-8, one string (or row) at is a :term:`generator` that encodes the Unicode strings as UTF-8, one string (or row) at
a time. The encoded strings are parsed by the CSV reader, and a time. The encoded strings are parsed by the CSV reader, and
:func:`unicode_csv_reader` decodes the UTF-8-encoded cells back into Unicode:: :func:`unicode_csv_reader` decodes the UTF-8-encoded cells back into Unicode::
......
...@@ -584,8 +584,8 @@ Nested structures can also be initialized in the constructor in several ways:: ...@@ -584,8 +584,8 @@ Nested structures can also be initialized in the constructor in several ways::
>>> r = RECT(POINT(1, 2), POINT(3, 4)) >>> r = RECT(POINT(1, 2), POINT(3, 4))
>>> r = RECT((1, 2), (3, 4)) >>> r = RECT((1, 2), (3, 4))
Fields descriptors can be retrieved from the *class*, they are useful for Field :term:`descriptor`\s can be retrieved from the *class*, they are useful
debugging because they can provide useful information:: for debugging because they can provide useful information::
>>> print(POINT.x) >>> print(POINT.x)
<Field type=c_long, ofs=0, size=4> <Field type=c_long, ofs=0, size=4>
...@@ -1195,10 +1195,10 @@ Another example that may behave different from what one would expect is this:: ...@@ -1195,10 +1195,10 @@ Another example that may behave different from what one would expect is this::
>>> >>>
Why is it printing ``False``? ctypes instances are objects containing a memory Why is it printing ``False``? ctypes instances are objects containing a memory
block plus some descriptors accessing the contents of the memory. Storing a block plus some :term:`descriptor`\s accessing the contents of the memory.
Python object in the memory block does not store the object itself, instead the Storing a Python object in the memory block does not store the object itself,
``contents`` of the object is stored. Accessing the contents again constructs a instead the ``contents`` of the object is stored. Accessing the contents again
new Python each time! constructs a new Python object each time!
.. _ctypes-variable-sized-data-types: .. _ctypes-variable-sized-data-types:
...@@ -1366,8 +1366,8 @@ way is to instantiate one of the following classes: ...@@ -1366,8 +1366,8 @@ way is to instantiate one of the following classes:
:class:`WinDLL` and :class:`OleDLL` use the standard calling convention on this :class:`WinDLL` and :class:`OleDLL` use the standard calling convention on this
platform. platform.
The Python GIL is released before calling any function exported by these The Python :term:`global interpreter lock` is released before calling any
libraries, and reacquired afterwards. function exported by these libraries, and reacquired afterwards.
.. class:: PyDLL(name, mode=DEFAULT_MODE, handle=None) .. class:: PyDLL(name, mode=DEFAULT_MODE, handle=None)
...@@ -1948,7 +1948,7 @@ Data types ...@@ -1948,7 +1948,7 @@ Data types
in case the memory block contains pointers. in case the memory block contains pointers.
Common methods of ctypes data types, these are all class methods (to be exact, Common methods of ctypes data types, these are all class methods (to be exact,
they are methods of the metaclass): they are methods of the :term:`metaclass`):
.. method:: _CData.from_address(address) .. method:: _CData.from_address(address)
...@@ -2263,7 +2263,7 @@ other data types containing pointer type fields. ...@@ -2263,7 +2263,7 @@ other data types containing pointer type fields.
Concrete structure and union types must be created by subclassing one of these Concrete structure and union types must be created by subclassing one of these
types, and at least define a :attr:`_fields_` class variable. ``ctypes`` will types, and at least define a :attr:`_fields_` class variable. ``ctypes`` will
create descriptors which allow reading and writing the fields by direct create :term:`descriptor`\s which allow reading and writing the fields by direct
attribute accesses. These are the attribute accesses. These are the
......
...@@ -174,7 +174,7 @@ floating point flying circus:: ...@@ -174,7 +174,7 @@ floating point flying circus::
>>> c % a >>> c % a
Decimal("0.77") Decimal("0.77")
And some mathematic functions are also available to Decimal:: And some mathematical functions are also available to Decimal::
>>> Decimal(2).sqrt() >>> Decimal(2).sqrt()
Decimal("1.414213562373095048801688724") Decimal("1.414213562373095048801688724")
......
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
.. % LaTeXification by Fred L. Drake, Jr. <fdrake@acm.org>. .. % LaTeXification by Fred L. Drake, Jr. <fdrake@acm.org>.
This module provides classes and functions for comparing sequences. It
can be used for example, for comparing files, and can produce difference
information in various formats, including HTML and context and unified
diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
.. class:: SequenceMatcher .. class:: SequenceMatcher
This is a flexible class for comparing pairs of sequences of any type, so long This is a flexible class for comparing pairs of sequences of any type, so long
...@@ -117,8 +122,8 @@ ...@@ -117,8 +122,8 @@
.. function:: context_diff(a, b[, fromfile][, tofile][, fromfiledate][, tofiledate][, n][, lineterm]) .. function:: context_diff(a, b[, fromfile][, tofile][, fromfiledate][, tofiledate][, n][, lineterm])
Compare *a* and *b* (lists of strings); return a delta (a generator generating Compare *a* and *b* (lists of strings); return a delta (a :term:`generator`
the delta lines) in context diff format. generating the delta lines) in context diff format.
Context diffs are a compact way of showing just the lines that have changed plus Context diffs are a compact way of showing just the lines that have changed plus
a few lines of context. The changes are shown in a before/after style. The a few lines of context. The changes are shown in a before/after style. The
...@@ -170,8 +175,8 @@ ...@@ -170,8 +175,8 @@
.. function:: ndiff(a, b[, linejunk][, charjunk]) .. function:: ndiff(a, b[, linejunk][, charjunk])
Compare *a* and *b* (lists of strings); return a :class:`Differ`\ -style delta Compare *a* and *b* (lists of strings); return a :class:`Differ`\ -style
(a generator generating the delta lines). delta (a :term:`generator` generating the delta lines).
Optional keyword parameters *linejunk* and *charjunk* are for filter functions Optional keyword parameters *linejunk* and *charjunk* are for filter functions
(or ``None``): (or ``None``):
...@@ -231,8 +236,8 @@ ...@@ -231,8 +236,8 @@
.. function:: unified_diff(a, b[, fromfile][, tofile][, fromfiledate][, tofiledate][, n][, lineterm]) .. function:: unified_diff(a, b[, fromfile][, tofile][, fromfiledate][, tofiledate][, n][, lineterm])
Compare *a* and *b* (lists of strings); return a delta (a generator generating Compare *a* and *b* (lists of strings); return a delta (a :term:`generator`
the delta lines) in unified diff format. generating the delta lines) in unified diff format.
Unified diffs are a compact way of showing just the lines that have changed plus Unified diffs are a compact way of showing just the lines that have changed plus
a few lines of context. The changes are shown in a inline style (instead of a few lines of context. The changes are shown in a inline style (instead of
...@@ -423,7 +428,7 @@ use :meth:`set_seq2` to set the commonly used sequence once and call ...@@ -423,7 +428,7 @@ use :meth:`set_seq2` to set the commonly used sequence once and call
.. method:: SequenceMatcher.get_grouped_opcodes([n]) .. method:: SequenceMatcher.get_grouped_opcodes([n])
Return a generator of groups with up to *n* lines of context. Return a :term:`generator` of groups with up to *n* lines of context.
Starting with the groups returned by :meth:`get_opcodes`, this method splits out Starting with the groups returned by :meth:`get_opcodes`, this method splits out
smaller change clusters and eliminates intervening ranges which have no changes. smaller change clusters and eliminates intervening ranges which have no changes.
......
:mod:`dis` --- Disassembler for Python byte code :mod:`dis` --- Disassembler for Python bytecode
================================================ ===============================================
.. module:: dis .. module:: dis
:synopsis: Disassembler for Python byte code. :synopsis: Disassembler for Python bytecode.
The :mod:`dis` module supports the analysis of Python byte code by disassembling The :mod:`dis` module supports the analysis of Python :term:`bytecode` by disassembling
it. Since there is no Python assembler, this module defines the Python assembly it. Since there is no Python assembler, this module defines the Python assembly
language. The Python byte code which this module takes as an input is defined language. The Python bytecode which this module takes as an input is defined
in the file :file:`Include/opcode.h` and used by the compiler and the in the file :file:`Include/opcode.h` and used by the compiler and the
interpreter. interpreter.
...@@ -35,7 +35,7 @@ The :mod:`dis` module defines the following functions and constants: ...@@ -35,7 +35,7 @@ The :mod:`dis` module defines the following functions and constants:
Disassemble the *bytesource* object. *bytesource* can denote either a module, a Disassemble the *bytesource* object. *bytesource* can denote either a module, a
class, a method, a function, or a code object. For a module, it disassembles class, a method, a function, or a code object. For a module, it disassembles
all functions. For a class, it disassembles all methods. For a single code all functions. For a class, it disassembles all methods. For a single code
sequence, it prints one line per byte code instruction. If no object is sequence, it prints one line per bytecode instruction. If no object is
provided, it disassembles the last traceback. provided, it disassembles the last traceback.
...@@ -70,12 +70,12 @@ The :mod:`dis` module defines the following functions and constants: ...@@ -70,12 +70,12 @@ The :mod:`dis` module defines the following functions and constants:
.. data:: opname .. data:: opname
Sequence of operation names, indexable using the byte code. Sequence of operation names, indexable using the bytecode.
.. data:: opmap .. data:: opmap
Dictionary mapping byte codes to operation names. Dictionary mapping bytecodes to operation names.
.. data:: cmp_op .. data:: cmp_op
...@@ -85,45 +85,45 @@ The :mod:`dis` module defines the following functions and constants: ...@@ -85,45 +85,45 @@ The :mod:`dis` module defines the following functions and constants:
.. data:: hasconst .. data:: hasconst
Sequence of byte codes that have a constant parameter. Sequence of bytecodes that have a constant parameter.
.. data:: hasfree .. data:: hasfree
Sequence of byte codes that access a free variable. Sequence of bytecodes that access a free variable.
.. data:: hasname .. data:: hasname
Sequence of byte codes that access an attribute by name. Sequence of bytecodes that access an attribute by name.
.. data:: hasjrel .. data:: hasjrel
Sequence of byte codes that have a relative jump target. Sequence of bytecodes that have a relative jump target.
.. data:: hasjabs .. data:: hasjabs
Sequence of byte codes that have an absolute jump target. Sequence of bytecodes that have an absolute jump target.
.. data:: haslocal .. data:: haslocal
Sequence of byte codes that access a local variable. Sequence of bytecodes that access a local variable.
.. data:: hascompare .. data:: hascompare
Sequence of byte codes of Boolean operations. Sequence of bytecodes of Boolean operations.
.. _bytecodes: .. _bytecodes:
Python Byte Code Instructions Python Bytecode Instructions
----------------------------- ----------------------------
The Python compiler currently generates the following byte code instructions. The Python compiler currently generates the following bytecode instructions.
.. opcode:: STOP_CODE () .. opcode:: STOP_CODE ()
...@@ -381,7 +381,7 @@ Miscellaneous opcodes. ...@@ -381,7 +381,7 @@ Miscellaneous opcodes.
.. opcode:: YIELD_VALUE () .. opcode:: YIELD_VALUE ()
Pops ``TOS`` and yields it from a generator. Pops ``TOS`` and yields it from a :term:`generator`.
.. opcode:: IMPORT_STAR () .. opcode:: IMPORT_STAR ()
...@@ -416,9 +416,9 @@ Miscellaneous opcodes. ...@@ -416,9 +416,9 @@ Miscellaneous opcodes.
context manager's :meth:`__exit__` bound method. Below that are 1--3 values context manager's :meth:`__exit__` bound method. Below that are 1--3 values
indicating how/why the finally clause was entered: indicating how/why the finally clause was entered:
* SECOND = None * SECOND = ``None``
* (SECOND, THIRD) = (WHY_{RETURN,CONTINUE}), retval * (SECOND, THIRD) = (``WHY_{RETURN,CONTINUE}``), retval
* SECOND = WHY_\*; no retval below it * SECOND = ``WHY_*``; no retval below it
* (SECOND, THIRD, FOURTH) = exc_info() * (SECOND, THIRD, FOURTH) = exc_info()
In the last case, ``TOS(SECOND, THIRD, FOURTH)`` is called, otherwise In the last case, ``TOS(SECOND, THIRD, FOURTH)`` is called, otherwise
...@@ -428,6 +428,8 @@ Miscellaneous opcodes. ...@@ -428,6 +428,8 @@ Miscellaneous opcodes.
returns a 'true' value, this information is "zapped", to prevent ``END_FINALLY`` returns a 'true' value, this information is "zapped", to prevent ``END_FINALLY``
from re-raising the exception. (But non-local gotos should still be resumed.) from re-raising the exception. (But non-local gotos should still be resumed.)
.. XXX explain the WHY stuff!
All of the following opcodes expect arguments. An argument is two bytes, with All of the following opcodes expect arguments. An argument is two bytes, with
the more significant byte last. the more significant byte last.
...@@ -548,32 +550,32 @@ the more significant byte last. ...@@ -548,32 +550,32 @@ the more significant byte last.
.. opcode:: JUMP_FORWARD (delta) .. opcode:: JUMP_FORWARD (delta)
Increments byte code counter by *delta*. Increments bytecode counter by *delta*.
.. opcode:: JUMP_IF_TRUE (delta) .. opcode:: JUMP_IF_TRUE (delta)
If TOS is true, increment the byte code counter by *delta*. TOS is left on the If TOS is true, increment the bytecode counter by *delta*. TOS is left on the
stack. stack.
.. opcode:: JUMP_IF_FALSE (delta) .. opcode:: JUMP_IF_FALSE (delta)
If TOS is false, increment the byte code counter by *delta*. TOS is not If TOS is false, increment the bytecode counter by *delta*. TOS is not
changed. changed.
.. opcode:: JUMP_ABSOLUTE (target) .. opcode:: JUMP_ABSOLUTE (target)
Set byte code counter to *target*. Set bytecode counter to *target*.
.. opcode:: FOR_ITER (delta) .. opcode:: FOR_ITER (delta)
``TOS`` is an iterator. Call its :meth:`__next__` method. If this yields a new ``TOS`` is an :term:`iterator`. Call its :meth:`__next__` method. If this
value, push it on the stack (leaving the iterator below it). If the iterator yields a new value, push it on the stack (leaving the iterator below it). If
indicates it is exhausted ``TOS`` is popped, and the byte code counter is the iterator indicates it is exhausted ``TOS`` is popped, and the byte code
incremented by *delta*. counter is incremented by *delta*.
.. % \begin{opcodedesc}{FOR_LOOP}{delta} .. % \begin{opcodedesc}{FOR_LOOP}{delta}
.. % This opcode is obsolete. .. % This opcode is obsolete.
......
...@@ -135,7 +135,7 @@ The following exceptions are the exceptions that are actually raised. ...@@ -135,7 +135,7 @@ The following exceptions are the exceptions that are actually raised.
.. exception:: GeneratorExit .. exception:: GeneratorExit
Raise when a generator's :meth:`close` method is called. Raise when a :term:`generator`\'s :meth:`close` method is called.
.. exception:: IOError .. exception:: IOError
...@@ -241,8 +241,8 @@ The following exceptions are the exceptions that are actually raised. ...@@ -241,8 +241,8 @@ The following exceptions are the exceptions that are actually raised.
.. exception:: StopIteration .. exception:: StopIteration
Raised by builtin :func:`next` and an iterator's :meth:`__next__` method to Raised by builtin :func:`next` and an :term:`iterator`\'s :meth:`__next__`
signal that there are no further values. method to signal that there are no further values.
.. exception:: SyntaxError .. exception:: SyntaxError
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
The :mod:`filecmp` module defines functions to compare files and directories, The :mod:`filecmp` module defines functions to compare files and directories,
with various optional time/correctness trade-offs. with various optional time/correctness trade-offs. For comparing files,
see also the :mod:`difflib` module.
The :mod:`filecmp` module defines the following functions: The :mod:`filecmp` module defines the following functions:
......
...@@ -41,7 +41,7 @@ available. They are listed here in alphabetical order. ...@@ -41,7 +41,7 @@ available. They are listed here in alphabetical order.
top-level package (the name up till the first dot) is returned, *not* the top-level package (the name up till the first dot) is returned, *not* the
module named by *name*. However, when a non-empty *fromlist* argument is module named by *name*. However, when a non-empty *fromlist* argument is
given, the module named by *name* is returned. This is done for given, the module named by *name* is returned. This is done for
compatibility with the bytecode generated for the different kinds of import compatibility with the :term:`bytecode` generated for the different kinds of import
statement; when using ``import spam.ham.eggs``, the top-level package statement; when using ``import spam.ham.eggs``, the top-level package
:mod:`spam` must be placed in the importing namespace, but when using ``from :mod:`spam` must be placed in the importing namespace, but when using ``from
spam.ham import eggs``, the ``spam.ham`` subpackage must be used to find the spam.ham import eggs``, the ``spam.ham`` subpackage must be used to find the
...@@ -317,7 +317,7 @@ available. They are listed here in alphabetical order. ...@@ -317,7 +317,7 @@ available. They are listed here in alphabetical order.
.. function:: enumerate(iterable) .. function:: enumerate(iterable)
Return an enumerate object. *iterable* must be a sequence, an iterator, or some Return an enumerate object. *iterable* must be a sequence, an :term:`iterator`, or some
other object which supports iteration. The :meth:`__next__` method of the other object which supports iteration. The :meth:`__next__` method of the
iterator returned by :func:`enumerate` returns a tuple containing a count (from iterator returned by :func:`enumerate` returns a tuple containing a count (from
zero) and the corresponding value obtained from iterating over *iterable*. zero) and the corresponding value obtained from iterating over *iterable*.
...@@ -340,7 +340,7 @@ available. They are listed here in alphabetical order. ...@@ -340,7 +340,7 @@ available. They are listed here in alphabetical order.
The *expression* argument is parsed and evaluated as a Python expression The *expression* argument is parsed and evaluated as a Python expression
(technically speaking, a condition list) using the *globals* and *locals* (technically speaking, a condition list) using the *globals* and *locals*
dictionaries as global and local name space. If the *globals* dictionary is dictionaries as global and local namespace. If the *globals* dictionary is
present and lacks '__builtins__', the current globals are copied into *globals* present and lacks '__builtins__', the current globals are copied into *globals*
before *expression* is parsed. This means that *expression* normally has full before *expression* is parsed. This means that *expression* normally has full
access to the standard :mod:`__builtin__` module and restricted environments are access to the standard :mod:`__builtin__` module and restricted environments are
...@@ -408,10 +408,9 @@ available. They are listed here in alphabetical order. ...@@ -408,10 +408,9 @@ available. They are listed here in alphabetical order.
Construct an iterator from those elements of *iterable* for which *function* Construct an iterator from those elements of *iterable* for which *function*
returns true. *iterable* may be either a sequence, a container which returns true. *iterable* may be either a sequence, a container which
supports iteration, or an iterator, If *iterable* is a string or a tuple, the supports iteration, or an iterator. If *function* is ``None``, the identity
result also has that type; otherwise it is always a list. If *function* is function is assumed, that is, all elements of *iterable* that are false are
``None``, the identity function is assumed, that is, all elements of removed.
*iterable* that are false are removed.
Note that ``filter(function, iterable)`` is equivalent to the generator Note that ``filter(function, iterable)`` is equivalent to the generator
expression ``(item for item in iterable if function(item))`` if function is expression ``(item for item in iterable if function(item))`` if function is
...@@ -543,15 +542,15 @@ available. They are listed here in alphabetical order. ...@@ -543,15 +542,15 @@ available. They are listed here in alphabetical order.
.. function:: int([x[, radix]]) .. function:: int([x[, radix]])
Convert a string or number to an integer. If the argument is a string, it Convert a string or number to an integer. If the argument is a string, it
must contain a possibly signed number of arbitrary size, must contain a possibly signed number of arbitrary size, possibly embedded in
possibly embedded in whitespace. The *radix* parameter gives the base for the whitespace. The *radix* parameter gives the base for the conversion (which
conversion and may be any integer in the range [2, 36], or zero. If *radix* is is 10 by default) and may be any integer in the range [2, 36], or zero. If
zero, the interpretation is the same as for integer literals. If *radix* is *radix* is zero, the interpretation is the same as for integer literals. If
specified and *x* is not a string, :exc:`TypeError` is raised. Otherwise, the *radix* is specified and *x* is not a string, :exc:`TypeError` is raised.
argument may be another integer, a floating point number or any other object Otherwise, the argument may be another integer, a floating point number or
that has an :meth:`__int__` method. Conversion any other object that has an :meth:`__int__` method. Conversion of floating
of floating point numbers to integers truncates (towards zero). If no point numbers to integers truncates (towards zero). If no arguments are
arguments are given, returns ``0``. given, returns ``0``.
The integer type is described in :ref:`typesnumeric`. The integer type is described in :ref:`typesnumeric`.
...@@ -577,7 +576,7 @@ available. They are listed here in alphabetical order. ...@@ -577,7 +576,7 @@ available. They are listed here in alphabetical order.
.. function:: iter(o[, sentinel]) .. function:: iter(o[, sentinel])
Return an iterator object. The first argument is interpreted very differently Return an :term:`iterator` object. The first argument is interpreted very differently
depending on the presence of the second argument. Without a second argument, *o* depending on the presence of the second argument. Without a second argument, *o*
must be a collection object which supports the iteration protocol (the must be a collection object which supports the iteration protocol (the
:meth:`__iter__` method), or it must support the sequence protocol (the :meth:`__iter__` method), or it must support the sequence protocol (the
...@@ -857,9 +856,9 @@ available. They are listed here in alphabetical order. ...@@ -857,9 +856,9 @@ available. They are listed here in alphabetical order.
.. function:: reversed(seq) .. function:: reversed(seq)
Return a reverse iterator. *seq* must be an object which supports the sequence Return a reverse :term:`iterator`. *seq* must be an object which supports
protocol (the :meth:`__len__` method and the :meth:`__getitem__` method with the sequence protocol (the :meth:`__len__` method and the :meth:`__getitem__`
integer arguments starting at ``0``). method with integer arguments starting at ``0``).
.. function:: round(x[, n]) .. function:: round(x[, n])
......
...@@ -28,8 +28,8 @@ subshell. (For tilde and shell variable expansion, use ...@@ -28,8 +28,8 @@ subshell. (For tilde and shell variable expansion, use
.. function:: iglob(pathname) .. function:: iglob(pathname)
Return an iterator which yields the same values as :func:`glob` without actually Return an :term:`iterator` which yields the same values as :func:`glob`
storing them all simultaneously. without actually storing them all simultaneously.
For example, consider a directory containing only the following files: For example, consider a directory containing only the following files:
......
...@@ -90,8 +90,8 @@ The module also offers three general purpose functions based on heaps. ...@@ -90,8 +90,8 @@ The module also offers three general purpose functions based on heaps.
.. function:: merge(*iterables) .. function:: merge(*iterables)
Merge multiple sorted inputs into a single sorted output (for example, merge Merge multiple sorted inputs into a single sorted output (for example, merge
timestamped entries from multiple log files). Returns an iterator over over the timestamped entries from multiple log files). Returns an :term:`iterator`
sorted values. over over the sorted values.
Similar to ``sorted(itertools.chain(*iterables))`` but returns an iterable, does Similar to ``sorted(itertools.chain(*iterables))`` but returns an iterable, does
not pull the data into memory all at once, and assumes that each of the input not pull the data into memory all at once, and assumes that each of the input
......
...@@ -67,7 +67,7 @@ attributes: ...@@ -67,7 +67,7 @@ attributes:
+-----------+-----------------+---------------------------+ +-----------+-----------------+---------------------------+
| | __code__ | code object containing | | | __code__ | code object containing |
| | | compiled function | | | | compiled function |
| | | bytecode | | | | :term:`bytecode` |
+-----------+-----------------+---------------------------+ +-----------+-----------------+---------------------------+
| | __defaults__ | tuple of any default | | | __defaults__ | tuple of any default |
| | | values for arguments | | | | values for arguments |
...@@ -253,30 +253,31 @@ attributes: ...@@ -253,30 +253,31 @@ attributes:
.. function:: ismethoddescriptor(object) .. function:: ismethoddescriptor(object)
Return true if the object is a method descriptor, but not if ismethod() or Return true if the object is a method descriptor, but not if :func:`ismethod`
isclass() or isfunction() are true. or :func:`isclass` or :func:`isfunction` are true.
This is new as of Python 2.2, and, for example, is true of int.__add__. An This is new as of Python 2.2, and, for example, is true of
object passing this test has a __get__ attribute but not a __set__ attribute, ``int.__add__``. An object passing this test has a :attr:`__get__` attribute
but beyond that the set of attributes varies. __name__ is usually sensible, and but not a :attr:`__set__` attribute, but beyond that the set of attributes
__doc__ often is. varies. :attr:`__name__` is usually sensible, and :attr:`__doc__` often is.
Methods implemented via descriptors that also pass one of the other tests return Methods implemented via descriptors that also pass one of the other tests
false from the ismethoddescriptor() test, simply because the other tests promise return false from the :func:`ismethoddescriptor` test, simply because the
more -- you can, e.g., count on having the im_func attribute (etc) when an other tests promise more -- you can, e.g., count on having the
object passes ismethod(). :attr:`im_func` attribute (etc) when an object passes :func:`ismethod`.
.. function:: isdatadescriptor(object) .. function:: isdatadescriptor(object)
Return true if the object is a data descriptor. Return true if the object is a data descriptor.
Data descriptors have both a __get__ and a __set__ attribute. Examples are Data descriptors have both a :attr:`__get__` and a :attr:`__set__` attribute.
properties (defined in Python), getsets, and members. The latter two are Examples are properties (defined in Python), getsets, and members. The
defined in C and there are more specific tests available for those types, which latter two are defined in C and there are more specific tests available for
is robust across Python implementations. Typically, data descriptors will also those types, which is robust across Python implementations. Typically, data
have __name__ and __doc__ attributes (properties, getsets, and members have both descriptors will also have :attr:`__name__` and :attr:`__doc__` attributes
of these attributes), but this is not guaranteed. (properties, getsets, and members have both of these attributes), but this is
not guaranteed.
.. function:: isgetsetdescriptor(object) .. function:: isgetsetdescriptor(object)
...@@ -293,8 +294,8 @@ attributes: ...@@ -293,8 +294,8 @@ attributes:
Return true if the object is a member descriptor. Return true if the object is a member descriptor.
Member descriptors are attributes defined in extension modules via Member descriptors are attributes defined in extension modules via
``PyMemberDef`` structures. For Python implementations without such types, this ``PyMemberDef`` structures. For Python implementations without such types,
method will always return ``False``. this method will always return ``False``.
.. _inspect-source: .. _inspect-source:
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
.. sectionauthor:: Raymond Hettinger <python@rcn.com> .. sectionauthor:: Raymond Hettinger <python@rcn.com>
This module implements a number of iterator building blocks inspired by This module implements a number of :term:`iterator` building blocks inspired by
constructs from the Haskell and SML programming languages. Each has been recast constructs from the Haskell and SML programming languages. Each has been recast
in a form suitable for Python. in a form suitable for Python.
...@@ -77,19 +77,15 @@ loops that truncate the stream. ...@@ -77,19 +77,15 @@ loops that truncate the stream.
.. function:: count([n]) .. function:: count([n])
Make an iterator that returns consecutive integers starting with *n*. If not Make an iterator that returns consecutive integers starting with *n*. If not
specified *n* defaults to zero. Does not currently support python long specified *n* defaults to zero. Often used as an argument to :func:`imap` to
integers. Often used as an argument to :func:`imap` to generate consecutive generate consecutive data points. Also, used with :func:`izip` to add sequence
data points. Also, used with :func:`izip` to add sequence numbers. Equivalent numbers. Equivalent to::
to::
def count(n=0): def count(n=0):
while True: while True:
yield n yield n
n += 1 n += 1
Note, :func:`count` does not check for overflow and will return negative numbers
after exceeding ``sys.maxint``. This behavior may change in the future.
.. function:: cycle(iterable) .. function:: cycle(iterable)
...@@ -451,8 +447,8 @@ The superior memory performance is kept by processing elements one at a time ...@@ -451,8 +447,8 @@ The superior memory performance is kept by processing elements one at a time
rather than bringing the whole iterable into memory all at once. Code volume is rather than bringing the whole iterable into memory all at once. Code volume is
kept small by linking the tools together in a functional style which helps kept small by linking the tools together in a functional style which helps
eliminate temporary variables. High speed is retained by preferring eliminate temporary variables. High speed is retained by preferring
"vectorized" building blocks over the use of for-loops and generators which "vectorized" building blocks over the use of for-loops and :term:`generator`\s
incur interpreter overhead. :: which incur interpreter overhead. ::
def take(n, seq): def take(n, seq):
return list(islice(seq, n)) return list(islice(seq, n))
......
...@@ -20,7 +20,7 @@ logging system for applications. ...@@ -20,7 +20,7 @@ logging system for applications.
Logging is performed by calling methods on instances of the :class:`Logger` Logging is performed by calling methods on instances of the :class:`Logger`
class (hereafter called :dfn:`loggers`). Each instance has a name, and they are class (hereafter called :dfn:`loggers`). Each instance has a name, and they are
conceptually arranged in a name space hierarchy using dots (periods) as conceptually arranged in a namespace hierarchy using dots (periods) as
separators. For example, a logger named "scan" is the parent of loggers separators. For example, a logger named "scan" is the parent of loggers
"scan.text", "scan.html" and "scan.pdf". Logger names can be anything you want, "scan.text", "scan.html" and "scan.pdf". Logger names can be anything you want,
and indicate the area of an application in which a logged message originates. and indicate the area of an application in which a logged message originates.
...@@ -430,7 +430,7 @@ instantiated directly, but always through the module-level function ...@@ -430,7 +430,7 @@ instantiated directly, but always through the module-level function
FORMAT = "%(asctime)-15s %(clientip)s %(user)-8s %(message)s" FORMAT = "%(asctime)-15s %(clientip)s %(user)-8s %(message)s"
logging.basicConfig(format=FORMAT) logging.basicConfig(format=FORMAT)
dict = { 'clientip' : '192.168.0.1', 'user' : 'fbloggs' } d = { 'clientip' : '192.168.0.1', 'user' : 'fbloggs' }
logger = logging.getLogger("tcpserver") logger = logging.getLogger("tcpserver")
logger.warning("Protocol problem: %s", "connection reset", extra=d) logger.warning("Protocol problem: %s", "connection reset", extra=d)
......
...@@ -805,7 +805,7 @@ follows: ...@@ -805,7 +805,7 @@ follows:
A message is typically moved from :file:`new` to :file:`cur` after its mailbox A message is typically moved from :file:`new` to :file:`cur` after its mailbox
has been accessed, whether or not the message is has been read. A message has been accessed, whether or not the message is has been read. A message
``msg`` has been read if ``"S" not in msg.get_flags()`` is ``True``. ``msg`` has been read if ``"S" in msg.get_flags()`` is ``True``.
.. method:: MaildirMessage.set_subdir(subdir) .. method:: MaildirMessage.set_subdir(subdir)
......
...@@ -25,7 +25,9 @@ transfer of Python objects through RPC calls, see the modules :mod:`pickle` and ...@@ -25,7 +25,9 @@ transfer of Python objects through RPC calls, see the modules :mod:`pickle` and
writing the "pseudo-compiled" code for Python modules of :file:`.pyc` files. writing the "pseudo-compiled" code for Python modules of :file:`.pyc` files.
Therefore, the Python maintainers reserve the right to modify the marshal format Therefore, the Python maintainers reserve the right to modify the marshal format
in backward incompatible ways should the need arise. If you're serializing and in backward incompatible ways should the need arise. If you're serializing and
de-serializing Python objects, use the :mod:`pickle` module instead. de-serializing Python objects, use the :mod:`pickle` module instead -- the
performance is comparable, version independence is guaranteed, and pickle
supports a substantially wider range of objects than marshal.
.. warning:: .. warning::
...@@ -36,12 +38,18 @@ de-serializing Python objects, use the :mod:`pickle` module instead. ...@@ -36,12 +38,18 @@ de-serializing Python objects, use the :mod:`pickle` module instead.
Not all Python object types are supported; in general, only objects whose value Not all Python object types are supported; in general, only objects whose value
is independent from a particular invocation of Python can be written and read by is independent from a particular invocation of Python can be written and read by
this module. The following types are supported: ``None``, integers, long this module. The following types are supported: ``None``, integers, long
integers, floating point numbers, strings, Unicode objects, tuples, lists, integers, floating point numbers, strings, Unicode objects, tuples, lists, sets,
dictionaries, and code objects, where it should be understood that tuples, lists dictionaries, and code objects, where it should be understood that tuples, lists
and dictionaries are only supported as long as the values contained therein are and dictionaries are only supported as long as the values contained therein are
themselves supported; and recursive lists and dictionaries should not be written themselves supported; and recursive lists and dictionaries should not be written
(they will cause infinite loops). (they will cause infinite loops).
.. warning::
Some unsupported types such as subclasses of builtins will appear to marshal
and unmarshal correctly, but in fact, their type will change and the
additional subclass functionality and instance attributes will be lost.
.. warning:: .. warning::
On machines where C's ``long int`` type has more than 32 bits (such as the On machines where C's ``long int`` type has more than 32 bits (such as the
......
...@@ -38,7 +38,7 @@ not update the underlying file. ...@@ -38,7 +38,7 @@ not update the underlying file.
To map anonymous memory, -1 should be passed as the fileno along with the length. To map anonymous memory, -1 should be passed as the fileno along with the length.
.. function:: mmap(fileno, length[, tagname[, access]]) .. function:: mmap(fileno, length[, tagname[, access[, offset]]])
**(Windows version)** Maps *length* bytes from the file specified by the file **(Windows version)** Maps *length* bytes from the file specified by the file
handle *fileno*, and returns a mmap object. If *length* is larger than the handle *fileno*, and returns a mmap object. If *length* is larger than the
...@@ -54,8 +54,12 @@ To map anonymous memory, -1 should be passed as the fileno along with the length ...@@ -54,8 +54,12 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
the mapping is created without a name. Avoiding the use of the tag parameter the mapping is created without a name. Avoiding the use of the tag parameter
will assist in keeping your code portable between Unix and Windows. will assist in keeping your code portable between Unix and Windows.
*offset* may be specified as a non-negative integer offset. mmap references will
be relative to the offset from the beginning of the file. *offset* defaults to 0.
*offset* must be a multiple of the ALLOCATIONGRANULARITY.
.. function:: mmap(fileno, length[, flags[, prot[, access]]])
.. function:: mmap(fileno, length[, flags[, prot[, access[, offset]]]])
:noindex: :noindex:
**(Unix version)** Maps *length* bytes from the file specified by the file **(Unix version)** Maps *length* bytes from the file specified by the file
...@@ -77,6 +81,10 @@ To map anonymous memory, -1 should be passed as the fileno along with the length ...@@ -77,6 +81,10 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
parameter. It is an error to specify both *flags*, *prot* and *access*. See parameter. It is an error to specify both *flags*, *prot* and *access*. See
the description of *access* above for information on how to use this parameter. the description of *access* above for information on how to use this parameter.
*offset* may be specified as a non-negative integer offset. mmap references will
be relative to the offset from the beginning of the file. *offset* defaults to 0.
*offset* must be a multiple of the PAGESIZE or ALLOCATIONGRANULARITY.
Memory-mapped file objects support the following methods: Memory-mapped file objects support the following methods:
...@@ -169,3 +177,4 @@ Memory-mapped file objects support the following methods: ...@@ -169,3 +177,4 @@ Memory-mapped file objects support the following methods:
created with :const:`ACCESS_READ`, then writing to it will throw a created with :const:`ACCESS_READ`, then writing to it will throw a
:exc:`TypeError` exception. :exc:`TypeError` exception.
...@@ -950,7 +950,7 @@ must specify for any option using that action. ...@@ -950,7 +950,7 @@ must specify for any option using that action.
* ``append_const`` [required: ``const``; relevant: :attr:`dest`] * ``append_const`` [required: ``const``; relevant: :attr:`dest`]
Like ``store_const``, but the value ``const`` is appended to :attr:`dest`; as Like ``store_const``, but the value ``const`` is appended to :attr:`dest`; as
with ``append``, :attr:`dest` defaults to ``None``, and an an empty list is with ``append``, :attr:`dest` defaults to ``None``, and an empty list is
automatically created the first time the option is encountered. automatically created the first time the option is encountered.
* ``count`` [relevant: :attr:`dest`] * ``count`` [relevant: :attr:`dest`]
...@@ -1116,7 +1116,7 @@ Integer arguments (type ``int`` or ``long``) are parsed as follows: ...@@ -1116,7 +1116,7 @@ Integer arguments (type ``int`` or ``long``) are parsed as follows:
* if the number starts with ``0``, it is parsed as an octal number * if the number starts with ``0``, it is parsed as an octal number
* if the number starts with ``0b``, is is parsed as a binary number * if the number starts with ``0b``, it is parsed as a binary number
* otherwise, the number is parsed as a decimal number * otherwise, the number is parsed as a decimal number
......
...@@ -279,8 +279,8 @@ write files see :func:`open`, and for accessing the filesystem see the ...@@ -279,8 +279,8 @@ write files see :func:`open`, and for accessing the filesystem see the
.. note:: .. note::
The newer :func:`os.walk` generator supplies similar functionality and can be The newer :func:`os.walk` :term:`generator` supplies similar functionality
easier to use. and can be easier to use.
.. data:: supports_unicode_filenames .. data:: supports_unicode_filenames
......
...@@ -109,7 +109,12 @@ process and user. ...@@ -109,7 +109,12 @@ process and user.
If the platform supports the :func:`unsetenv` function, you can delete items in If the platform supports the :func:`unsetenv` function, you can delete items in
this mapping to unset environment variables. :func:`unsetenv` will be called this mapping to unset environment variables. :func:`unsetenv` will be called
automatically when an item is deleted from ``os.environ``. automatically when an item is deleted from ``os.environ``, and when
one of the :meth:`pop` or :meth:`clear` methods is called.
.. versionchanged:: 2.6
Also unset environment variables when calling :meth:`os.environ.clear`
and :meth:`os.environ.pop`.
.. function:: chdir(path) .. function:: chdir(path)
...@@ -541,7 +546,7 @@ by file descriptors. ...@@ -541,7 +546,7 @@ by file descriptors.
.. function:: ttyname(fd) .. function:: ttyname(fd)
Return a string which specifies the terminal device associated with Return a string which specifies the terminal device associated with
file-descriptor *fd*. If *fd* is not associated with a terminal device, an file descriptor *fd*. If *fd* is not associated with a terminal device, an
exception is raised. Availability:Macintosh, Unix. exception is raised. Availability:Macintosh, Unix.
......
...@@ -321,7 +321,7 @@ Examples ...@@ -321,7 +321,7 @@ Examples
.. index:: builtin: compile .. index:: builtin: compile
The parser modules allows operations to be performed on the parse tree of Python The parser modules allows operations to be performed on the parse tree of Python
source code before the bytecode is generated, and provides for inspection of the source code before the :term:`bytecode` is generated, and provides for inspection of the
parse tree for information gathering purposes. Two examples are presented. The parse tree for information gathering purposes. Two examples are presented. The
simple example demonstrates emulation of the :func:`compile` built-in function simple example demonstrates emulation of the :func:`compile` built-in function
and the complex example shows the use of a parse tree for information discovery. and the complex example shows the use of a parse tree for information discovery.
......
...@@ -239,7 +239,7 @@ commands [*bpnumber*] ...@@ -239,7 +239,7 @@ commands [*bpnumber*]
Specifying any command resuming execution (currently continue, step, next, Specifying any command resuming execution (currently continue, step, next,
return, jump, quit and their abbreviations) terminates the command list (as if return, jump, quit and their abbreviations) terminates the command list (as if
that command was immediately followed by end). This is because any time you that command was immediately followed by end). This is because any time you
resume execution (even with a simple next or step), you may encounter· another resume execution (even with a simple next or step), you may encounter another
breakpoint--which could have its own command list, leading to ambiguities about breakpoint--which could have its own command list, leading to ambiguities about
which list to execute. which list to execute.
...@@ -323,7 +323,7 @@ unalias *name* ...@@ -323,7 +323,7 @@ unalias *name*
(Pdb) (Pdb)
run [*args* ...] run [*args* ...]
Restart the debugged python program. If an argument is supplied, it is splitted Restart the debugged python program. If an argument is supplied, it is split
with "shlex" and the result is used as the new sys.argv. History, breakpoints, with "shlex" and the result is used as the new sys.argv. History, breakpoints,
actions and debugger options are preserved. "restart" is an alias for "run". actions and debugger options are preserved. "restart" is an alias for "run".
......
...@@ -122,7 +122,7 @@ There are currently 3 different protocols which can be used for pickling. ...@@ -122,7 +122,7 @@ There are currently 3 different protocols which can be used for pickling.
earlier versions of Python. earlier versions of Python.
* Protocol version 2 was introduced in Python 2.3. It provides much more * Protocol version 2 was introduced in Python 2.3. It provides much more
efficient pickling of new-style classes. efficient pickling of :term:`new-style class`\es.
Refer to :pep:`307` for more information. Refer to :pep:`307` for more information.
...@@ -418,8 +418,8 @@ New-style types can provide a :meth:`__getnewargs__` method that is used for ...@@ -418,8 +418,8 @@ New-style types can provide a :meth:`__getnewargs__` method that is used for
protocol 2. Implementing this method is needed if the type establishes some protocol 2. Implementing this method is needed if the type establishes some
internal invariants when the instance is created, or if the memory allocation is internal invariants when the instance is created, or if the memory allocation is
affected by the values passed to the :meth:`__new__` method for the type (as it affected by the values passed to the :meth:`__new__` method for the type (as it
is for tuples and strings). Instances of a new-style type :class:`C` are is for tuples and strings). Instances of a :term:`new-style class` :class:`C`
created using :: are created using ::
obj = C.__new__(C, *args) obj = C.__new__(C, *args)
...@@ -447,8 +447,8 @@ can do what they want. [#]_ ...@@ -447,8 +447,8 @@ can do what they want. [#]_
.. warning:: .. warning::
For new-style classes, if :meth:`__getstate__` returns a false value, the For :term:`new-style class`\es, if :meth:`__getstate__` returns a false
:meth:`__setstate__` method will not be called. value, the :meth:`__setstate__` method will not be called.
Pickling and unpickling extension types Pickling and unpickling extension types
......
...@@ -27,8 +27,8 @@ probably won't find the :mod:`pickletools` module relevant. ...@@ -27,8 +27,8 @@ probably won't find the :mod:`pickletools` module relevant.
.. function:: genops(pickle) .. function:: genops(pickle)
Provides an iterator over all of the opcodes in a pickle, returning a sequence Provides an :term:`iterator` over all of the opcodes in a pickle, returning a
of ``(opcode, arg, pos)`` triples. *opcode* is an instance of an sequence of ``(opcode, arg, pos)`` triples. *opcode* is an instance of an
:class:`OpcodeInfo` class; *arg* is the decoded value, as a Python object, of :class:`OpcodeInfo` class; *arg* is the decoded value, as a Python object, of
the opcode's argument; *pos* is the position at which this opcode is located. the opcode's argument; *pos* is the position at which this opcode is located.
*pickle* can be a string or a file-like object. *pickle* can be a string or a file-like object.
......
...@@ -43,6 +43,6 @@ The :mod:`pty` module defines the following functions: ...@@ -43,6 +43,6 @@ The :mod:`pty` module defines the following functions:
reading from the controlling terminal. reading from the controlling terminal.
The functions *master_read* and *stdin_read* should be functions which read from The functions *master_read* and *stdin_read* should be functions which read from
a file-descriptor. The defaults try to read 1024 bytes each time they are a file descriptor. The defaults try to read 1024 bytes each time they are
called. called.
...@@ -19,10 +19,10 @@ in Python, including many standard and optional extension modules. ...@@ -19,10 +19,10 @@ in Python, including many standard and optional extension modules.
.. function:: readmodule(module[, path]) .. function:: readmodule(module[, path])
Read a module and return a dictionary mapping class names to class descriptor Read a module and return a dictionary mapping class names to class descriptor
objects. The parameter *module* should be the name of a module as a string; it objects. The parameter *module* should be the name of a module as a string;
may be the name of a module within a package. The *path* parameter should be a it may be the name of a module within a package. The *path* parameter should
sequence, and is used to augment the value of ``sys.path``, which is used to be a sequence, and is used to augment the value of ``sys.path``, which is
locate module source code. used to locate module source code.
.. % The 'inpackage' parameter appears to be for internal use only.... .. % The 'inpackage' parameter appears to be for internal use only....
......
...@@ -28,8 +28,8 @@ The solution is to use Python's raw string notation for regular expression ...@@ -28,8 +28,8 @@ The solution is to use Python's raw string notation for regular expression
patterns; backslashes are not handled in any special way in a string literal patterns; backslashes are not handled in any special way in a string literal
prefixed with ``'r'``. So ``r"\n"`` is a two-character string containing prefixed with ``'r'``. So ``r"\n"`` is a two-character string containing
``'\'`` and ``'n'``, while ``"\n"`` is a one-character string containing a ``'\'`` and ``'n'``, while ``"\n"`` is a one-character string containing a
newline. Usually patterns will be expressed in Python code using this raw string newline. Usually patterns will be expressed in Python code using this raw
notation. string notation.
.. seealso:: .. seealso::
...@@ -427,8 +427,8 @@ form. ...@@ -427,8 +427,8 @@ form.
.. function:: compile(pattern[, flags]) .. function:: compile(pattern[, flags])
Compile a regular expression pattern into a regular expression object, which can Compile a regular expression pattern into a regular expression object, which
be used for matching using its :func:`match` and :func:`search` methods, can be used for matching using its :func:`match` and :func:`search` methods,
described below. described below.
The expression's behaviour can be modified by specifying a *flags* value. The expression's behaviour can be modified by specifying a *flags* value.
...@@ -444,8 +444,8 @@ form. ...@@ -444,8 +444,8 @@ form.
result = re.match(pat, str) result = re.match(pat, str)
but the version using :func:`compile` is more efficient when the expression will but the version using :func:`compile` is more efficient when the expression
be used several times in a single program. will be used several times in a single program.
.. % (The compiled version of the last pattern passed to .. % (The compiled version of the last pattern passed to
.. % \function{re.match()} or \function{re.search()} is cached, so .. % \function{re.match()} or \function{re.search()} is cached, so
...@@ -463,8 +463,8 @@ form. ...@@ -463,8 +463,8 @@ form.
.. data:: L .. data:: L
LOCALE LOCALE
Make ``\w``, ``\W``, ``\b``, ``\B``, ``\s`` and ``\S`` dependent on the current Make ``\w``, ``\W``, ``\b``, ``\B``, ``\s`` and ``\S`` dependent on the
locale. current locale.
.. data:: M .. data:: M
...@@ -556,17 +556,18 @@ form. ...@@ -556,17 +556,18 @@ form.
.. function:: findall(pattern, string[, flags]) .. function:: findall(pattern, string[, flags])
Return a list of all non-overlapping matches of *pattern* in *string*. If one Return all non-overlapping matches of *pattern* in *string*, as a list of
or more groups are present in the pattern, return a list of groups; this will be strings. If one or more groups are present in the pattern, return a list of
a list of tuples if the pattern has more than one group. Empty matches are groups; this will be a list of tuples if the pattern has more than one group.
included in the result unless they touch the beginning of another match. Empty matches are included in the result unless they touch the beginning of
another match.
.. function:: finditer(pattern, string[, flags]) .. function:: finditer(pattern, string[, flags])
Return an iterator over all non-overlapping matches for the RE *pattern* in Return an :term:`iterator` yielding :class:`MatchObject` instances over all
*string*. For each match, the iterator returns a match object. Empty matches non-overlapping matches for the RE *pattern* in *string*. Empty matches are
are included in the result unless they touch the beginning of another match. included in the result unless they touch the beginning of another match.
.. function:: sub(pattern, repl, string[, count]) .. function:: sub(pattern, repl, string[, count])
...@@ -729,7 +730,9 @@ attributes: ...@@ -729,7 +730,9 @@ attributes:
Match Objects Match Objects
------------- -------------
:class:`MatchObject` instances support the following methods and attributes: Match objects always have a boolean value of :const:`True`, so that you can test
whether e.g. :func:`match` resulted in a match with a simple if statement. They
support the following methods and attributes:
.. method:: MatchObject.expand(template) .. method:: MatchObject.expand(template)
......
...@@ -70,9 +70,9 @@ may use a different placeholder, such as ``%s`` or ``:1``.) For example:: ...@@ -70,9 +70,9 @@ may use a different placeholder, such as ``%s`` or ``:1``.) For example::
c.execute('insert into stocks values (?,?,?,?,?)', t) c.execute('insert into stocks values (?,?,?,?,?)', t)
To retrieve data after executing a SELECT statement, you can either treat the To retrieve data after executing a SELECT statement, you can either treat the
cursor as an iterator, call the cursor's :meth:`fetchone` method to retrieve a cursor as an :term:`iterator`, call the cursor's :meth:`fetchone` method to
single matching row, or call :meth:`fetchall` to get a list of the matching retrieve a single matching row, or call :meth:`fetchall` to get a list of the
rows. matching rows.
This example uses the iterator form:: This example uses the iterator form::
...@@ -408,13 +408,13 @@ A :class:`Cursor` instance has the following attributes and methods: ...@@ -408,13 +408,13 @@ A :class:`Cursor` instance has the following attributes and methods:
.. method:: Cursor.executemany(sql, seq_of_parameters) .. method:: Cursor.executemany(sql, seq_of_parameters)
Executes a SQL command against all parameter sequences or mappings found in the Executes a SQL command against all parameter sequences or mappings found in
sequence *sql*. The :mod:`sqlite3` module also allows using an iterator yielding the sequence *sql*. The :mod:`sqlite3` module also allows using an
parameters instead of a sequence. :term:`iterator` yielding parameters instead of a sequence.
.. literalinclude:: ../includes/sqlite3/executemany_1.py .. literalinclude:: ../includes/sqlite3/executemany_1.py
Here's a shorter example using a generator: Here's a shorter example using a :term:`generator`:
.. literalinclude:: ../includes/sqlite3/executemany_2.py .. literalinclude:: ../includes/sqlite3/executemany_2.py
......
...@@ -223,7 +223,7 @@ Functions, Constants, and Exceptions ...@@ -223,7 +223,7 @@ Functions, Constants, and Exceptions
.. data:: PROTOCOL_TLSv1 .. data:: PROTOCOL_TLSv1
Selects SSL version 2 as the channel encryption protocol. This is Selects TLS version 1 as the channel encryption protocol. This is
the most modern version, and probably the best choice for maximum the most modern version, and probably the best choice for maximum
protection, if both sides can speak it. protection, if both sides can speak it.
......
...@@ -449,10 +449,10 @@ Once an iterator's :meth:`__next__` method raises :exc:`StopIteration`, it must ...@@ -449,10 +449,10 @@ Once an iterator's :meth:`__next__` method raises :exc:`StopIteration`, it must
continue to do so on subsequent calls. Implementations that do not obey this continue to do so on subsequent calls. Implementations that do not obey this
property are deemed broken. property are deemed broken.
Python's generators provide a convenient way to implement the iterator protocol. Python's :term:`generator`\s provide a convenient way to implement the iterator
If a container object's :meth:`__iter__` method is implemented as a generator, protocol. If a container object's :meth:`__iter__` method is implemented as a
it will automatically return an iterator object (technically, a generator generator, it will automatically return an iterator object (technically, a
object) supplying the :meth:`__iter__` and :meth:`__next__` methods. generator object) supplying the :meth:`__iter__` and :meth:`__next__` methods.
.. _typesseq: .. _typesseq:
...@@ -655,9 +655,9 @@ functions based on regular expressions. ...@@ -655,9 +655,9 @@ functions based on regular expressions.
.. method:: str.count(sub[, start[, end]]) .. method:: str.count(sub[, start[, end]])
Return the number of occurrences of substring *sub* in string S\ Return the number of occurrences of substring *sub* in the range [*start*,
``[start:end]``. Optional arguments *start* and *end* are interpreted as in *end*]. Optional arguments *start* and *end* are interpreted as in slice
slice notation. notation.
.. method:: str.encode([encoding[, errors]]) .. method:: str.encode([encoding[, errors]])
...@@ -682,8 +682,11 @@ functions based on regular expressions. ...@@ -682,8 +682,11 @@ functions based on regular expressions.
.. method:: str.expandtabs([tabsize]) .. method:: str.expandtabs([tabsize])
Return a copy of the string where all tab characters are expanded using spaces. Return a copy of the string where all tab characters are replaced by one or
If *tabsize* is not given, a tab size of ``8`` characters is assumed. more spaces, depending on the current column and the given tab size. The
column number is reset to zero after each newline occurring in the string.
If *tabsize* is not given, a tab size of ``8`` characters is assumed. This
doesn't understand other non-printing characters or escape sequences.
.. method:: str.find(sub[, start[, end]]) .. method:: str.find(sub[, start[, end]])
...@@ -869,19 +872,23 @@ functions based on regular expressions. ...@@ -869,19 +872,23 @@ functions based on regular expressions.
string. If *maxsplit* is given, at most *maxsplit* splits are done (thus, string. If *maxsplit* is given, at most *maxsplit* splits are done (thus,
the list will have at most ``maxsplit+1`` elements). If *maxsplit* is not the list will have at most ``maxsplit+1`` elements). If *maxsplit* is not
specified, then there is no limit on the number of splits (all possible specified, then there is no limit on the number of splits (all possible
splits are made). Consecutive delimiters are not grouped together and are splits are made).
If *sep is given, consecutive delimiters are not grouped together and are
deemed to delimit empty strings (for example, ``'1,,2'.split(',')`` returns deemed to delimit empty strings (for example, ``'1,,2'.split(',')`` returns
``['1', '', '2']``). The *sep* argument may consist of multiple characters ``['1', '', '2']``). The *sep* argument may consist of multiple characters
(for example, ``'1, 2, 3'.split(', ')`` returns ``['1', '2', '3']``). (for example, ``'1<>2<>3'.split('<>')`` returns ``['1', '2', '3']``).
Splitting an empty string with a specified separator returns ``['']``. Splitting an empty string with a specified separator returns ``['']``.
If *sep* is not specified or is ``None``, a different splitting algorithm is If *sep* is not specified or is ``None``, a different splitting algorithm is
applied. First, whitespace characters (spaces, tabs, newlines, returns, and applied: runs of consecutive whitespace are regarded as a single separator,
formfeeds) are stripped from both ends. Then, words are separated by arbitrary and the result will contain no empty strings at the start or end if the
length strings of whitespace characters. Consecutive whitespace delimiters are string has leading or trailing whitespace. Consequently, splitting an empty
treated as a single delimiter (``'1 2 3'.split()`` returns ``['1', '2', string or a string consisting of just whitespace with a ``None`` separator
'3']``). Splitting an empty string or a string consisting of just whitespace returns ``[]``.
returns an empty list.
For example, ``' 1 2 3 '.split()`` returns ``['1', '2', '3']``, and
``' 1 2 3 '.split(None, 1)`` returns ``['1', '2 3 ']``.
.. method:: str.splitlines([keepends]) .. method:: str.splitlines([keepends])
...@@ -947,8 +954,10 @@ functions based on regular expressions. ...@@ -947,8 +954,10 @@ functions based on regular expressions.
.. method:: str.zfill(width) .. method:: str.zfill(width)
Return the numeric string left filled with zeros in a string of length *width*. Return the numeric string left filled with zeros in a string of length
The original string is returned if *width* is less than ``len(s)``. *width*. A sign prefix is handled correctly. The original string is
returned if *width* is less than ``len(s)``.
.. _old-string-formatting: .. _old-string-formatting:
...@@ -1865,8 +1874,7 @@ Files have the following methods: ...@@ -1865,8 +1874,7 @@ Files have the following methods:
.. method:: file.fileno() .. method:: file.fileno()
.. index:: .. index::
single: file descriptor pair: file; descriptor
single: descriptor, file
module: fcntl module: fcntl
Return the integer "file descriptor" that is used by the underlying Return the integer "file descriptor" that is used by the underlying
...@@ -2091,7 +2099,7 @@ to be provided for a context manager object to define a runtime context: ...@@ -2091,7 +2099,7 @@ to be provided for a context manager object to define a runtime context:
.. method:: contextmanager.__exit__(exc_type, exc_val, exc_tb) .. method:: contextmanager.__exit__(exc_type, exc_val, exc_tb)
Exit the runtime context and return a Boolean flag indicating if any expection Exit the runtime context and return a Boolean flag indicating if any exception
that occurred should be suppressed. If an exception occurred while executing the that occurred should be suppressed. If an exception occurred while executing the
body of the :keyword:`with` statement, the arguments contain the exception type, body of the :keyword:`with` statement, the arguments contain the exception type,
value and traceback information. Otherwise, all three arguments are ``None``. value and traceback information. Otherwise, all three arguments are ``None``.
...@@ -2115,7 +2123,7 @@ decimal arithmetic context. The specific types are not treated specially beyond ...@@ -2115,7 +2123,7 @@ decimal arithmetic context. The specific types are not treated specially beyond
their implementation of the context management protocol. See the their implementation of the context management protocol. See the
:mod:`contextlib` module for some examples. :mod:`contextlib` module for some examples.
Python's generators and the ``contextlib.contextfactory`` decorator provide a Python's :term:`generator`\s and the ``contextlib.contextfactory`` decorator provide a
convenient way to implement these protocols. If a generator function is convenient way to implement these protocols. If a generator function is
decorated with the ``contextlib.contextfactory`` decorator, it will return a decorated with the ``contextlib.contextfactory`` decorator, it will return a
context manager implementing the necessary :meth:`__enter__` and context manager implementing the necessary :meth:`__enter__` and
......
...@@ -13,7 +13,7 @@ implemented in Python. The scanner in this module returns comments as tokens as ...@@ -13,7 +13,7 @@ implemented in Python. The scanner in this module returns comments as tokens as
well, making it useful for implementing "pretty-printers," including colorizers well, making it useful for implementing "pretty-printers," including colorizers
for on-screen displays. for on-screen displays.
The primary entry point is a generator: The primary entry point is a :term:`generator`:
.. function:: generate_tokens(readline) .. function:: generate_tokens(readline)
......
...@@ -113,8 +113,8 @@ The module defines the following names: ...@@ -113,8 +113,8 @@ The module defines the following names:
.. data:: GeneratorType .. data:: GeneratorType
The type of generator-iterator objects, produced by calling a generator The type of :term:`generator`-iterator objects, produced by calling a
function. generator function.
.. data:: CodeType .. data:: CodeType
......
...@@ -29,7 +29,7 @@ It defines the following public functions: ...@@ -29,7 +29,7 @@ It defines the following public functions:
:exc:`IOError` exception is raised. If all went well, a file-like object is :exc:`IOError` exception is raised. If all went well, a file-like object is
returned. This supports the following methods: :meth:`read`, :meth:`readline`, returned. This supports the following methods: :meth:`read`, :meth:`readline`,
:meth:`readlines`, :meth:`fileno`, :meth:`close`, :meth:`info` and :meth:`readlines`, :meth:`fileno`, :meth:`close`, :meth:`info` and
:meth:`geturl`. It also has proper support for the iterator protocol. One :meth:`geturl`. It also has proper support for the :term:`iterator` protocol. One
caveat: the :meth:`read` method, if the size argument is omitted or negative, caveat: the :meth:`read` method, if the size argument is omitted or negative,
may not read until the end of the data stream; there is no good way to determine may not read until the end of the data stream; there is no good way to determine
that the entire stream from a socket has been read in the general case. that the entire stream from a socket has been read in the general case.
......
...@@ -51,9 +51,9 @@ is exposed by the :mod:`weakref` module for the benefit of advanced uses. ...@@ -51,9 +51,9 @@ is exposed by the :mod:`weakref` module for the benefit of advanced uses.
Not all objects can be weakly referenced; those objects which can include class Not all objects can be weakly referenced; those objects which can include class
instances, functions written in Python (but not in C), methods (both bound and instances, functions written in Python (but not in C), methods (both bound and
unbound), sets, frozensets, file objects, generators, type objects, DBcursor unbound), sets, frozensets, file objects, :term:`generator`\s, type objects,
objects from the :mod:`bsddb` module, sockets, arrays, deques, and regular :class:`DBcursor` objects from the :mod:`bsddb` module, sockets, arrays, deques,
expression pattern objects. and regular expression pattern objects.
Several builtin types such as :class:`list` and :class:`dict` do not directly Several builtin types such as :class:`list` and :class:`dict` do not directly
support weak references but can add support through subclassing:: support weak references but can add support through subclassing::
...@@ -146,7 +146,7 @@ than needed. ...@@ -146,7 +146,7 @@ than needed.
.. method:: WeakKeyDictionary.iterkeyrefs() .. method:: WeakKeyDictionary.iterkeyrefs()
Return an iterator that yields the weak references to the keys. Return an :term:`iterator` that yields the weak references to the keys.
.. method:: WeakKeyDictionary.keyrefs() .. method:: WeakKeyDictionary.keyrefs()
...@@ -174,7 +174,7 @@ methods of :class:`WeakKeyDictionary` objects. ...@@ -174,7 +174,7 @@ methods of :class:`WeakKeyDictionary` objects.
.. method:: WeakValueDictionary.itervaluerefs() .. method:: WeakValueDictionary.itervaluerefs()
Return an iterator that yields the weak references to the values. Return an :term:`iterator` that yields the weak references to the values.
.. method:: WeakValueDictionary.valuerefs() .. method:: WeakValueDictionary.valuerefs()
......
...@@ -124,7 +124,7 @@ also provides these miscellaneous utilities: ...@@ -124,7 +124,7 @@ also provides these miscellaneous utilities:
.. class:: FileWrapper(filelike [, blksize=8192]) .. class:: FileWrapper(filelike [, blksize=8192])
A wrapper to convert a file-like object to an iterator. The resulting objects A wrapper to convert a file-like object to an :term:`iterator`. The resulting objects
support both :meth:`__getitem__` and :meth:`__iter__` iteration styles, for support both :meth:`__getitem__` and :meth:`__iter__` iteration styles, for
compatibility with Python 2.1 and Jython. As the object is iterated over, the compatibility with Python 2.1 and Jython. As the object is iterated over, the
optional *blksize* parameter will be repeatedly passed to the *filelike* optional *blksize* parameter will be repeatedly passed to the *filelike*
......
...@@ -87,7 +87,7 @@ Functions ...@@ -87,7 +87,7 @@ Functions
Parses an XML section into an element tree incrementally, and reports what's Parses an XML section into an element tree incrementally, and reports what's
going on to the user. *source* is a filename or file object containing XML data. going on to the user. *source* is a filename or file object containing XML data.
*events* is a list of events to report back. If omitted, only "end" events are *events* is a list of events to report back. If omitted, only "end" events are
reported. Returns an iterator providing ``(event, elem)`` pairs. reported. Returns an :term:`iterator` providing ``(event, elem)`` pairs.
.. function:: parse(source[, parser]) .. function:: parse(source[, parser])
...@@ -316,7 +316,7 @@ ElementTree Objects ...@@ -316,7 +316,7 @@ ElementTree Objects
.. method:: ElementTree.findall(path) .. method:: ElementTree.findall(path)
Finds all toplevel elements with the given tag. Same as getroot().findall(path). Finds all toplevel elements with the given tag. Same as getroot().findall(path).
*path* is the element to look for. Returns a list or iterator containing all *path* is the element to look for. Returns a list or :term:`iterator` containing all
matching elements, in document order. matching elements, in document order.
......
...@@ -314,7 +314,8 @@ encapsulate multiple calls to a remote server into a single request. ...@@ -314,7 +314,8 @@ encapsulate multiple calls to a remote server into a single request.
return ``None``, and only store the call name and parameters in the return ``None``, and only store the call name and parameters in the
:class:`MultiCall` object. Calling the object itself causes all stored calls to :class:`MultiCall` object. Calling the object itself causes all stored calls to
be transmitted as a single ``system.multicall`` request. The result of this call be transmitted as a single ``system.multicall`` request. The result of this call
is a generator; iterating over this generator yields the individual results. is a :term:`generator`; iterating over this generator yields the individual
results.
A usage example of this class is :: A usage example of this class is ::
......
...@@ -852,7 +852,7 @@ Internal types ...@@ -852,7 +852,7 @@ Internal types
single: bytecode single: bytecode
object: code object: code
Code objects represent *byte-compiled* executable Python code, or *bytecode*. Code objects represent *byte-compiled* executable Python code, or :term:`bytecode`.
The difference between a code object and a function object is that the function The difference between a code object and a function object is that the function
object contains an explicit reference to the function's globals (the module in object contains an explicit reference to the function's globals (the module in
which it was defined), while a code object contains no context; also the default which it was defined), while a code object contains no context; also the default
...@@ -873,7 +873,7 @@ Internal types ...@@ -873,7 +873,7 @@ Internal types
used by the bytecode; :attr:`co_names` is a tuple containing the names used by used by the bytecode; :attr:`co_names` is a tuple containing the names used by
the bytecode; :attr:`co_filename` is the filename from which the code was the bytecode; :attr:`co_filename` is the filename from which the code was
compiled; :attr:`co_firstlineno` is the first line number of the function; compiled; :attr:`co_firstlineno` is the first line number of the function;
:attr:`co_lnotab` is a string encoding the mapping from byte code offsets to :attr:`co_lnotab` is a string encoding the mapping from bytecode offsets to
line numbers (for details see the source code of the interpreter); line numbers (for details see the source code of the interpreter);
:attr:`co_stacksize` is the required stack size (including local variables); :attr:`co_stacksize` is the required stack size (including local variables);
:attr:`co_flags` is an integer encoding a number of flags for the interpreter. :attr:`co_flags` is an integer encoding a number of flags for the interpreter.
...@@ -1039,6 +1039,7 @@ Internal types ...@@ -1039,6 +1039,7 @@ Internal types
.. % ========================================================================= .. % =========================================================================
.. _newstyle:
.. _specialnames: .. _specialnames:
......
...@@ -1273,7 +1273,9 @@ groups from right to left). ...@@ -1273,7 +1273,9 @@ groups from right to left).
.. [#] While comparisons between strings make sense at the byte level, they may .. [#] While comparisons between strings make sense at the byte level, they may
be counter-intuitive to users. For example, the strings ``"\u00C7"`` and be counter-intuitive to users. For example, the strings ``"\u00C7"`` and
``"\u0327\u0043"`` compare differently, even though they both represent the ``"\u0327\u0043"`` compare differently, even though they both represent the
same unicode character (LATIN CAPTITAL LETTER C WITH CEDILLA). same unicode character (LATIN CAPTITAL LETTER C WITH CEDILLA). To compare
strings in a human recognizable way, compare using
:func:`unicodedata.normalize`.
.. [#] The implementation computes this efficiently, without constructing lists .. [#] The implementation computes this efficiently, without constructing lists
or sorting. or sorting.
......
...@@ -497,7 +497,7 @@ call-next-method and is more powerful than the super call found in ...@@ -497,7 +497,7 @@ call-next-method and is more powerful than the super call found in
single-inheritance languages. single-inheritance languages.
Dynamic ordering is necessary because all cases of multiple inheritance exhibit Dynamic ordering is necessary because all cases of multiple inheritance exhibit
one or more diamond relationships (where one at least one of the parent classes one or more diamond relationships (where at least one of the parent classes
can be accessed through multiple paths from the bottommost class). For example, can be accessed through multiple paths from the bottommost class). For example,
all classes inherit from :class:`object`, so any case of multiple inheritance all classes inherit from :class:`object`, so any case of multiple inheritance
provides more than one path to reach :class:`object`. To keep the base classes provides more than one path to reach :class:`object`. To keep the base classes
...@@ -707,12 +707,12 @@ returns an object with a :meth:`__next__` method. If the class defines ...@@ -707,12 +707,12 @@ returns an object with a :meth:`__next__` method. If the class defines
Generators Generators
========== ==========
Generators are a simple and powerful tool for creating iterators. They are :term:`Generator`\s are a simple and powerful tool for creating iterators. They
written like regular functions but use the :keyword:`yield` statement whenever are written like regular functions but use the :keyword:`yield` statement
they want to return data. Each time :func:`next` is called on it, the generator whenever they want to return data. Each time :func:`next` is called on it, the
resumes where it left-off (it remembers all the data values and which statement generator resumes where it left-off (it remembers all the data values and which
was last executed). An example shows that generators can be trivially easy to statement was last executed). An example shows that generators can be trivially
create:: easy to create::
def reverse(data): def reverse(data):
for index in range(len(data)-1, -1, -1): for index in range(len(data)-1, -1, -1):
......
...@@ -266,8 +266,9 @@ like in C, procedures are just functions that don't return a value. In fact, ...@@ -266,8 +266,9 @@ like in C, procedures are just functions that don't return a value. In fact,
technically speaking, procedures do return a value, albeit a rather boring one. technically speaking, procedures do return a value, albeit a rather boring one.
This value is called ``None`` (it's a built-in name). Writing the value This value is called ``None`` (it's a built-in name). Writing the value
``None`` is normally suppressed by the interpreter if it would be the only value ``None`` is normally suppressed by the interpreter if it would be the only value
written. You can see it if you really want to:: written. You can see it if you really want to using :keyword:`print`::
>>> fib(0)
>>> print(fib(0)) >>> print(fib(0))
None None
......
...@@ -123,7 +123,7 @@ interpreter. :: ...@@ -123,7 +123,7 @@ interpreter. ::
# bound to the Esc key by default (you can change it - see readline docs). # bound to the Esc key by default (you can change it - see readline docs).
# #
# Store the file in ~/.pystartup, and set an environment variable to point # Store the file in ~/.pystartup, and set an environment variable to point
# to it: "export PYTHONSTARTUP=/max/home/itamar/.pystartup" in bash. # to it: "export PYTHONSTARTUP=/home/user/.pystartup" in bash.
# #
# Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the # Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
# full path to your home directory. # full path to your home directory.
......
...@@ -191,8 +191,8 @@ Some tips for experts: ...@@ -191,8 +191,8 @@ Some tips for experts:
* When the Python interpreter is invoked with the :option:`-O` flag, optimized * When the Python interpreter is invoked with the :option:`-O` flag, optimized
code is generated and stored in :file:`.pyo` files. The optimizer currently code is generated and stored in :file:`.pyo` files. The optimizer currently
doesn't help much; it only removes :keyword:`assert` statements. When doesn't help much; it only removes :keyword:`assert` statements. When
:option:`-O` is used, *all* bytecode is optimized; ``.pyc`` files are ignored :option:`-O` is used, *all* :term:`bytecode` is optimized; ``.pyc`` files are
and ``.py`` files are compiled to optimized bytecode. ignored and ``.py`` files are compiled to optimized bytecode.
* Passing two :option:`-O` flags to the Python interpreter (:option:`-OO`) will * Passing two :option:`-O` flags to the Python interpreter (:option:`-OO`) will
cause the bytecode compiler to perform optimizations that could in some rare cause the bytecode compiler to perform optimizations that could in some rare
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment