py-docs-2004 / 2.1 /python21_docs.jsonl
Harley-ml's picture
Upload 2.1/python21_docs.jsonl
c363098 verified
Raw
History Blame
210 kB
{"title": "About the Python Documentation", "text": "./ | About the Python Documentation\nUp:\nPython Documentation Index (./)\n---\n## About the Python Documentation\nThe Python documentation was originally written by Guido van\nRossum, but has increasingly become a community effort over the\npast several years. This growing collection of documents is\navailable in several formats, including typeset versions in PDF\nand PostScript for printing, from the Python Web site (http://www.python.org/).\nA list of contributors (acks.html) is available.\n## Comments and Questions\nGeneral comments and questions regarding this document should\nbe sent by email to python-docs@python.org (mailto:python-docs@python.org). If you find specific errors in\nthis document, please report the bug at the Python Bug\nTracker (http://sourceforge.net/bugs/?group_id=5470) at SourceForge (http://sourceforge.net/).\nQuestions regarding how to use the information in this\ndocument should be sent to the Python news group, comp.lang.python (news:comp.lang.python), or the Python mailing list (http://www.python.org/mailman/listinfo/python-list) (which is gated to the newsgroup and\ncarries the same content).\nFor any of these channels, please be sure not to send HTML email.\nThanks.\n---", "python_version": "2.1", "length": 1201, "url": "https://docs.python.org/2.0/about.html"}
{"title": "Acknowledgements", "text": "./ | Acknowledgements\n---\n## Acknowledgements\nThese people have contributed in some way to the Python\ndocumentation. This list is probably not complete -- if you feel that\nyou or anyone else should be on this list, please let us know (send\nemail to python-docs@python.org (mailto:python-docs@python.org)), and\nwe will be glad to correct the problem.\nIt is only with the input and contributions of the Python community\nthat Python has such wonderful documentation -- Thank You!\nJim Ahlstrom | Anders Hammarquist | Everett Lipman | Constantina S.\nA. Amoroso | Mark Hammond | Mirko Liss | Hugh Sasse\nPehr Anderson | Manus Hand | Martin von Lwis | Bob Savage\nOliver Andrich | Travis B. Hartwell | Fredrik Lundh | Scott Schram\nDaniel Barclay | Janko Hauser | Jeff MacDonald | Neil Schemenauer\nChris Barker | Bernhard Herzog | John Machin | Barry Scott\nDon Bashford | Magnus L. Hetland | Andrew MacIntyre | Joakim Sernbrant\nAnthony Baxter | Konrad Hinsen | Vladimir Marangozov | Justin Sheehy\nBennett Benson | Stefan Hoffmeister | Vincent Marchetti | Michael Simcich\nJonathan Black | Albert Hofkamp | Aahz Maruch | Ionel Simionescu\nRobin Boerdijk | Gregor Hoffleit | Laura Matson | Roy Smith\nMichal Bozon | Steve Holden | Daniel May | Clay Spence\nAaron Brancotti | Gerrit Holl | Doug Mennella | Nicholas Spies\nKeith Briggs | Rob Hooft | Paolo Milani | Tage Stabell-Kulo\nLee Busby | Brian Hooper | Skip Montanaro | Frank Stajano\nLorenzo M. Catucci | Randall Hopper | Ross Moore | Anthony Starks\nMauro Cicognini | Michael Hudson | Sjoerd Mullender | Greg Stein\nGilles Civario | Jeremy Hylton | Dale Nagata | Peter Stoehr\nSteve Clift | Roger Irwin | Ng Pheng Siong | Mark Summerfield\nAndrew Dalke | Jack Jansen | Koray Oner | Reuben Sumner\nBen Darnell | Philip H. Jensen | Denis S. Otkidach | Jim Tittsler\nRobert Donohue | Pedro Diaz Jimenez | William Park | Martijn Vries\nFred L. Drake, Jr. | Lucas de Jonge | Tim Peters | Charles G. Waldman\nJeff Epler | Andreas Jung | Christopher Petrilli | Greg Ward\nMichael Ernst | Robert Kern | Justin D. Pettit | Barry Warsaw\nBlame Andy Eskilsson | Jim Kerr | Chris Phoenix | Corran Webster\nMartijn Faassen | Jan Kim | Franois Pinard | Glyn Webster\nCarl Feynman | Greg Kochanski | Paul Prescod | Bob Weiner\nHernan Martinez Foffani | Guido Kollerie | Eric S. Raymond | Eddy Welbourne\nStefan Franke | Peter A. Koren | Edward K. Ream | Gerry Wiener\nJim Fulton | Daniel Kozan | Sean Reifschneider | Timothy Wild\nPeter Funk | Andrew M. Kuchling | Bernhard Reiter | Blake Winton\nLele Gaifax | Erno Kuusela | Wes Rishel | Dan Wolfe\nMatthew Gallagher | Detlef Lannert | Jim Roskind | Steven Work\nBen Gertzfield | Piers Lauder | Guido van Rossum | Thomas Wouters\nNadim Ghaznavi | Glyph Lefkowitz | Donald Wallace Rouse II | Ka-Ping Yee\nJonathan Giddy | Marc-Andr Lemburg | Nick Russo | Moshe Zadka\nGrant Griffin | Ulf A. Lindgren | Chris Ryland | Cheng Zhang\n---\n./ | Acknowledgements", "python_version": "2.1", "length": 2906, "url": "https://docs.python.org/2.0/acks.html"}
{"title": "About this document ...", "text": "genindex.html | api.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# About this document ...\nPython/C API Reference Manual,\nApril 15, 2001, Release 2.1\nThis document was generated using the LaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) translator.\nLaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) is Copyright ©\n1993, 1994, 1995, 1996, 1997, Nikos\nDrakos (http://cbl.leeds.ac.uk/nikos/personal.html), Computer Based Learning Unit, University of\nLeeds, and Copyright © 1997, 1998, Ross\nMoore (http://www.maths.mq.edu.au/~ross/), Mathematics Department, Macquarie University,\nSydney.\nThe application of LaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) to the Python\ndocumentation has been heavily tailored by Fred L. Drake,\nJr. Original navigation icons were contributed by Christopher\nPetrilli.\n---\n## Comments and Questions\nGeneral comments and questions regarding this document should\nbe sent by email to python-docs@python.org (mailto:python-docs@python.org). If you find specific errors in\nthis document, please report the bug at the Python Bug\nTracker (http://sourceforge.net/bugs/?group_id=5470) at SourceForge (http://sourceforge.net/).\nQuestions regarding how to use the information in this\ndocument should be sent to the Python news group, comp.lang.python (news:comp.lang.python), or the Python mailing list (http://www.python.org/mailman/listinfo/python-list) (which is gated to the newsgroup and\ncarries the same content).\nFor any of these channels, please be sure not to send HTML email.\nThanks.\n---\ngenindex.html | api.html | Python/C API Reference Manual | contents.html | genindex.html\n---\nRelease 2.1, documentation updated on April 15, 2001.", "python_version": "2.1", "length": 1717, "url": "https://docs.python.org/2.0/api/about.html"}
{"title": "6. Abstract Objects Layer", "text": "importing.html | api.html | object.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 6. Abstract Objects Layer\nThe functions in this chapter interact with Python objects regardless\nof their type, or with wide classes of object types (e.g. all\nnumerical types, or all sequence types). When used on object types\nfor which they do not apply, they will raise a Python exception.", "python_version": "2.1", "length": 399, "url": "https://docs.python.org/2.0/api/abstract.html"}
{"title": "Python/C API Reference Manual", "text": "../index.html | front.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# Python/C API Reference Manual\nGuido van Rossum\nFred L. Drake, Jr., editor\nPythonLabs\nE-mail: python-docs@python.org\nRelease 2.1\nApril 15, 2001", "python_version": "2.1", "length": 239, "url": "https://docs.python.org/2.0/api/api.html"}
{"title": "10.5 Buffer Object Structures", "text": "sequence-structs.html | newTypes.html | supporting-cycle-detection.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 10.5 Buffer Object Structures\nThe buffer interface exports a model where an object can expose its\ninternal data as a set of chunks of data, where each chunk is\nspecified as a pointer/length pair. These chunks are called\nsegments and are presumed to be non-contiguous in memory.\nIf an object does not export the buffer interface, then its\ntp_as_buffer member in the PyTypeObject structure\nshould be NULL. Otherwise, the tp_as_buffer will point to\na PyBufferProcs structure.\nNote: It is very important that your\nPyTypeObject structure uses Py_TPFLAGS_DEFAULT for\nthe value of the tp_flags member rather than `0`. This\ntells the Python runtime that your PyBufferProcs structure\ncontains the bf_getcharbuffer slot. Older versions of Python\ndid not have this member, so a new Python interpreter using an old\nextension needs to be able to test for its presence before using it.", "python_version": "2.1", "length": 1013, "url": "https://docs.python.org/2.0/api/buffer-structs.html"}
{"title": "7.2.3 Buffer Objects", "text": "unicodeMethodsAndSlots.html | sequenceObjects.html | tupleObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.2.3 Buffer Objects\nPython objects implemented in C can export a group of functions called\nthe ``bufferinterface.'' These functions can\nbe used by an object to expose its data in a raw, byte-oriented\nformat. Clients of the object can use the buffer interface to access\nthe object data directly, without needing to copy it first.\nTwo examples of objects that support\nthe buffer interface are strings and arrays. The string object exposes\nthe character contents in the buffer interface's byte-oriented\nform. An array can also expose its contents, but it should be noted\nthat array elements may be multi-byte values.\nAn example user of the buffer interface is the file object's\nwrite() method. Any object that can export a series of bytes\nthrough the buffer interface can be written to a file. There are a\nnumber of format codes to PyArgs_ParseTuple() that operate\nagainst an object's buffer interface, returning data from the target\nobject.\nMore information on the buffer interface is provided in the section\n``Buffer Object Structures'' (section 10.5 (buffer-structs.html#buffer-structs)), under\nthe description for PyBufferProcs.\nA ``buffer object'' is defined in the bufferobject.h header\n(included by Python.h). These objects look very similar to\nstring objects at the Python programming level: they support slicing,\nindexing, concatenation, and some other standard string\noperations. However, their data can come from one of two sources: from\na block of memory, or from another object which exports the buffer\ninterface.\nBuffer objects are useful as a way to expose the data from another\nobject's buffer interface to the Python programmer. They can also be\nused as a zero-copy slicing mechanism. Using their ability to\nreference a block of memory, it is possible to expose any data to the\nPython programmer quite easily. The memory could be a large, constant\narray in a C extension, it could be a raw block of memory for\nmanipulation before passing to an operating system library, or it\ncould be used to pass around structured data in its native, in-memory\nformat.", "python_version": "2.1", "length": 2210, "url": "https://docs.python.org/2.0/api/bufferObjects.html"}
{"title": "7.2.2.1 Builtin Codecs", "text": "unicodeObjects.html | unicodeObjects.html | unicodeMethodsAndSlots.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n### 7.2.2.1 Builtin Codecs\nPython provides a set of builtin codecs which are written in C\nfor speed. All of these codecs are directly usable via the\nfollowing functions.\nMany of the following APIs take two arguments encoding and\nerrors. These parameters encoding and errors have the same semantics\nas the ones of the builtin unicode() Unicode object constructor.\nSetting encoding to NULL causes the default encoding to be used which\nis UTF-8.\nError handling is set by errors which may also be set to NULL meaning\nto use the default handling defined for the codec. Default error\nhandling for all builtin codecs is ``strict'' (ValueErrors are raised).\nThe codecs all use a similar interface. Only deviation from the\nfollowing generic ones are documented for simplicity.\nThese are the generic codec APIs:\nThese are the UTF-8 codec APIs:\nThese are the UTF-16 codec APIs:\nThese are the ``Unicode Esacpe'' codec APIs:\nThese are the ``Raw Unicode Esacpe'' codec APIs:\nThese are the Latin-1 codec APIs:\nLatin-1 corresponds to the first 256 Unicode ordinals and only these\nare accepted by the codecs during encoding.\nThese are the ASCII codec APIs. Only 7-bit ASCII data is\naccepted. All other codes generate errors.\nThese are the mapping codec APIs:\nThis codec is special in that it can be used to implement many\ndifferent codecs (and this is in fact what was done to obtain most of\nthe standard codecs included in the encodings package). The\ncodec uses mapping to encode and decode characters.\nDecoding mappings must map single string characters to single Unicode\ncharacters, integers (which are then interpreted as Unicode ordinals)\nor None (meaning \"undefined mapping\" and causing an error).\nEncoding mappings must map single Unicode characters to single string\ncharacters, integers (which are then interpreted as Latin-1 ordinals)\nor None (meaning \"undefined mapping\" and causing an error).\nThe mapping objects provided must only support the __getitem__ mapping\ninterface.\nIf a character lookup fails with a LookupError, the character is\ncopied as-is meaning that its ordinal value will be interpreted as\nUnicode or Latin-1 ordinal resp. Because of this, mappings only need\nto contain those mappings which map characters to different code\npoints.\nThe following codec API is special in that maps Unicode to Unicode.\nThese are the MBCS codec APIs. They are currently only available on\nWindows and use the Win32 MBCS converters to implement the\nconversions. Note that MBCS (or DBCS) is a class of encodings, not\njust one. The target encoding is defined by the user settings on the\nmachine running the codec.", "python_version": "2.1", "length": 2740, "url": "https://docs.python.org/2.0/api/builtinCodecs.html"}
{"title": "7.5.4 CObjects", "text": "moduleObjects.html | otherObjects.html | initialization.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.5.4 CObjects\nRefer to Extending and Embedding the Python Interpreter,\nsection 1.12 (``Providing a C API for an Extension Module''), for more\ninformation on using these objects.", "python_version": "2.1", "length": 310, "url": "https://docs.python.org/2.0/api/cObjects.html"}
{"title": "10.1 Common Object Structures", "text": "newTypes.html | newTypes.html | mapping-structs.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 10.1 Common Object Structures\nPyObject, PyVarObject\nPyObject_HEAD, PyObject_HEAD_INIT, PyObject_VAR_HEAD\nTypedefs:\nunaryfunc, binaryfunc, ternaryfunc, inquiry, coercion, intargfunc,\nintintargfunc, intobjargproc, intintobjargproc, objobjargproc,\ndestructor, printfunc, getattrfunc, getattrofunc, setattrfunc,\nsetattrofunc, cmpfunc, reprfunc, hashfunc", "python_version": "2.1", "length": 472, "url": "https://docs.python.org/2.0/api/common-structs.html"}
{"title": "7.4.4 Complex Number Objects", "text": "floatObjects.html | numericObjects.html | node44.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.4.4 Complex Number Objects\nPython's complex number objects are implemented as two distinct types\nwhen viewed from the C API: one is the Python object exposed to\nPython programs, and the other is a C structure which represents the\nactual complex number value. The API provides functions for working\nwith both.", "python_version": "2.1", "length": 435, "url": "https://docs.python.org/2.0/api/complexObjects.html"}
{"title": "7. Concrete Objects Layer", "text": "mapping.html | api.html | fundamental.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 7. Concrete Objects Layer\nThe functions in this chapter are specific to certain Python object\ntypes. Passing them an object of the wrong type is not a good idea;\nif you receive an object from a Python program and you are not sure\nthat it has the right type, you must perform a type check first;\nfor example, to check that an object is a dictionary, use\nPyDict_Check(). The chapter is structured like the\n``family tree'' of Python object types.\nWarning:\nWhile the functions described in this chapter carefully check the type\nof the objects which are passed in, many of them do not check for\nNULL being passed instead of a valid object. Allowing NULL to\nbe passed in can cause memory access violations and immediate\ntermination of the interpreter.", "python_version": "2.1", "length": 858, "url": "https://docs.python.org/2.0/api/concrete.html"}
{"title": "Contents", "text": "front.html | api.html | intro.html | Python/C API Reference Manual | genindex.html\n---\n## Contents\nTable of Contents\n- Front Matter (front.html)\n 1. Introduction (intro.html)\n - 1.1 Include Files (includes.html)\n 1.2 Objects, Types and Reference Counts (objects.html)\n - 1.2.1 Reference Counts (refcounts.html)\n 1.2.2 Types (types.html)\n 1.3 Exceptions (exceptions.html)\n 1.4 Embedding Python (embedding.html)\n 2. The Very High Level Layer (veryhigh.html)\n 3. Reference Counting (countingRefs.html)\n 4. Exception Handling (exceptionHandling.html)\n - 4.1 Standard Exceptions (standardExceptions.html)\n 4.2 Deprecation of String Exceptions (node15.html)\n 5. Utilities (utilities.html)\n - 5.1 OS Utilities (os.html)\n 5.2 Process Control (processControl.html)\n 5.3 Importing Modules (importing.html)\n 6. Abstract Objects Layer (abstract.html)\n - 6.1 Object Protocol (object.html)\n 6.2 Number Protocol (number.html)\n 6.3 Sequence Protocol (sequence.html)\n 6.4 Mapping Protocol (mapping.html)\n 7. Concrete Objects Layer (concrete.html)\n - 7.1 Fundamental Objects (fundamental.html)\n - 7.1.1 Type Objects (typeObjects.html)\n 7.1.2 The None Object (noneObject.html)\n 7.2 Sequence Objects (sequenceObjects.html)\n - 7.2.1 String Objects (stringObjects.html)\n 7.2.2 Unicode Objects (unicodeObjects.html)\n 7.2.3 Buffer Objects (bufferObjects.html)\n 7.2.4 Tuple Objects (tupleObjects.html)\n 7.2.5 List Objects (listObjects.html)\n 7.3 Mapping Objects (mapObjects.html)\n - 7.3.1 Dictionary Objects (dictObjects.html)\n 7.4 Numeric Objects (numericObjects.html)\n - 7.4.1 Plain Integer Objects (intObjects.html)\n 7.4.2 Long Integer Objects (longObjects.html)\n 7.4.3 Floating Point Objects (floatObjects.html)\n 7.4.4 Complex Number Objects (complexObjects.html)\n 7.5 Other Objects (otherObjects.html)\n - 7.5.1 File Objects (fileObjects.html)\n 7.5.2 Instance Objects (instanceObjects.html)\n 7.5.3 Module Objects (moduleObjects.html)\n 7.5.4 CObjects (cObjects.html)\n 8. Initialization, Finalization, and Threads (initialization.html)\n - 8.1 Thread State and the Global Interpreter Lock (threads.html)\n 9. Memory Management (memory.html)\n - 9.1 Overview (memoryOverview.html)\n 9.2 Memory Interface (memoryInterface.html)\n 9.3 Examples (memoryExamples.html)\n 10. Defining New Object Types (newTypes.html)\n - 10.1 Common Object Structures (common-structs.html)\n 10.2 Mapping Object Structures (mapping-structs.html)\n 10.3 Number Object Structures (number-structs.html)\n 10.4 Sequence Object Structures (sequence-structs.html)\n 10.5 Buffer Object Structures (buffer-structs.html)\n 10.6 Supporting Cyclic Garbarge Collection (supporting-cycle-detection.html)\n - 10.6.1 Example Cycle Collector Support (example-cycle-support.html)\n A. Reporting Bugs (reporting-bugs.html)\n About this document ... (about.html)\nEnd of Table of Contents", "python_version": "2.1", "length": 2866, "url": "https://docs.python.org/2.0/api/contents.html"}
{"title": "3. Reference Counting", "text": "veryhigh.html | api.html | exceptionHandling.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 3. Reference Counting\nThe macros in this section are used for managing reference counts\nof Python objects.\nThe following functions or macros are only for use within the\ninterpreter core: _Py_Dealloc(),\n_Py_ForgetReference(), _Py_NewReference(), as\nwell as the global variable _Py_RefTotal.", "python_version": "2.1", "length": 409, "url": "https://docs.python.org/2.0/api/countingRefs.html"}
{"title": "7.3.1 Dictionary Objects", "text": "mapObjects.html | mapObjects.html | numericObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.3.1 Dictionary Objects", "python_version": "2.1", "length": 151, "url": "https://docs.python.org/2.0/api/dictObjects.html"}
{"title": "1.4 Embedding Python", "text": "exceptions.html | intro.html | veryhigh.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 1.4 Embedding Python\nThe one important task that only embedders (as opposed to extension\nwriters) of the Python interpreter have to worry about is the\ninitialization, and possibly the finalization, of the Python\ninterpreter. Most functionality of the interpreter can only be used\nafter the interpreter has been initialized.\nThe basic initialization function is\nPy_Initialize().\nThis initializes the table of loaded modules, and creates the\nfundamental modules __builtin__,\n__main__and\nsys. It also initializes the module\nsearch path (`sys.path`).\nPy_Initialize() does not set the ``script argument list''\n(`sys.argv`). If this variable is needed by Python code that\nwill be executed later, it must be set explicitly with a call to\n`PySys_SetArgv( argc , argv )`subsequent to the call to\nPy_Initialize().\nOn most systems (in particular, on Unix and Windows, although the\ndetails are slightly different),\nPy_Initialize() calculates the module search path based\nupon its best guess for the location of the standard Python\ninterpreter executable, assuming that the Python library is found in a\nfixed location relative to the Python interpreter executable. In\nparticular, it looks for a directory named\nlib/python2.1 relative to the parent directory where\nthe executable named python is found on the shell command\nsearch path (the environment variable PATH).\nFor instance, if the Python executable is found in\n/usr/local/bin/python, it will assume that the libraries are in\n/usr/local/lib/python2.1. (In fact, this particular path\nis also the ``fallback'' location, used when no executable file named\npython is found along PATH.) The user can override\nthis behavior by setting the environment variable PYTHONHOME,\nor insert additional directories in front of the standard path by\nsetting PYTHONPATH.\nThe embedding application can steer the search by calling\n`Py_SetProgramName( file )`before calling\nPy_Initialize(). Note that PYTHONHOME still\noverrides this and PYTHONPATH is still inserted in front of\nthe standard path. An application that requires total control has to\nprovide its own implementation of\nPy_GetPath(),\nPy_GetPrefix(),\nPy_GetExecPrefix(), and\nPy_GetProgramFullPath()(all\ndefined in Modules/getpath.c).\nSometimes, it is desirable to ``uninitialize'' Python. For instance,\nthe application may want to start over (make another call to\nPy_Initialize()) or the application is simply done with its\nuse of Python and wants to free all memory allocated by Python. This\ncan be accomplished by calling Py_Finalize(). The function\nPy_IsInitialized()returns\ntrue if Python is currently in the initialized state. More\ninformation about these functions is given in a later chapter.", "python_version": "2.1", "length": 2795, "url": "https://docs.python.org/2.0/api/embedding.html"}
{"title": "10.6.1 Example Cycle Collector Support", "text": "supporting-cycle-detection.html | supporting-cycle-detection.html | reporting-bugs.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 10.6.1 Example Cycle Collector Support\nThis example shows only enough of the implementation of an extension\ntype to show how the garbage collector support needs to be added. It\nshows the definition of the object structure, the\ntp_traverse, tp_clear and tp_dealloc\nimplementations, the type structure, and a constructor -- the module\ninitialization needed to export the constructor to Python is not shown\nas there are no special considerations there for the collector. To\nmake this interesting, assume that the module exposes ways for the\ncontainer field of the object to be modified. Note that\nsince no checks are made on the type of the object used to initialize\ncontainer, we have to assume that it may be a container.\n```text\n\n#include \"Python.h\"\n\ntypedef struct {\nPyObject_HEAD\nPyObject *container;\n} MyObject;\n\nstatic int\nmy_traverse(MyObject *self, visitproc visit, void *arg)\n{\nif (self->container != NULL)\nreturn visit(self->container, arg);\nelse\nreturn 0;\n}\n\nstatic int\nmy_clear(MyObject *self)\n{\nPy_XDECREF(self->container);\nself->container = NULL;\n\nreturn 0;\n}\n\nstatic void\nmy_dealloc(MyObject *self)\n{\nPyObject_GC_Fini((PyObject *) self);\nPy_XDECREF(self->container);\nPyObject_Del(self);\n}\n```\n```text\n\nstatichere PyTypeObject\nMyObject_Type = {\nPyObject_HEAD_INIT(NULL)\n0,\n\"MyObject\",\nsizeof(MyObject) + PyGC_HEAD_SIZE,\n0,\n(destructor)my_dealloc, /* tp_dealloc */\n0, /* tp_print */\n0, /* tp_getattr */\n0, /* tp_setattr */\n0, /* tp_compare */\n0, /* tp_repr */\n0, /* tp_as_number */\n0, /* tp_as_sequence */\n0, /* tp_as_mapping */\n0, /* tp_hash */\n0, /* tp_call */\n0, /* tp_str */\n0, /* tp_getattro */\n0, /* tp_setattro */\n0, /* tp_as_buffer */\nPy_TPFLAGS_DEFAULT | Py_TPFLAGS_GC,\n0, /* tp_doc */\n(traverseproc)my_traverse, /* tp_traverse */\n(inquiry)my_clear, /* tp_clear */\n0, /* tp_richcompare */\n0, /* tp_weaklistoffset */\n};\n\n/* This constructor should be made accessible from Python. */\nstatic PyObject *\nnew_object(PyObject *unused, PyObject *args)\n{\nPyObject *container = NULL;\nMyObject *result = NULL;\n\nif (PyArg_ParseTuple(args, \"|O:new_object\", &container)) {\nresult = PyObject_New(MyObject, &MyObject_Type);\nif (result != NULL) {\nresult->container = container;\nPyObject_GC_Init();\n}\n}\nreturn (PyObject *) result;\n}\n```", "python_version": "2.1", "length": 2398, "url": "https://docs.python.org/2.0/api/example-cycle-support.html"}
{"title": "4. Exception Handling", "text": "countingRefs.html | api.html | standardExceptions.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 4. Exception Handling\nThe functions described in this chapter will let you handle and raise Python\nexceptions. It is important to understand some of the basics of\nPython exception handling. It works somewhat like the\nUnix errno variable: there is a global indicator (per\nthread) of the last error that occurred. Most functions don't clear\nthis on success, but will set it to indicate the cause of the error on\nfailure. Most functions also return an error indicator, usually\nNULL if they are supposed to return a pointer, or `-1` if they\nreturn an integer (exception: the PyArg_Parse*() functions\nreturn `1` for success and `0` for failure). When a\nfunction must fail because some function it called failed, it\ngenerally doesn't set the error indicator; the function it called\nalready set it.\nThe error indicator consists of three Python objects corresponding to\nthe Python variables `sys.exc_type`, `sys.exc_value` and\n`sys.exc_traceback`. API functions exist to interact with the\nerror indicator in various ways. There is a separate error indicator\nfor each thread.", "python_version": "2.1", "length": 1191, "url": "https://docs.python.org/2.0/api/exceptionHandling.html"}
{"title": "1.3 Exceptions", "text": "types.html | intro.html | embedding.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 1.3 Exceptions\nThe Python programmer only needs to deal with exceptions if specific\nerror handling is required; unhandled exceptions are automatically\npropagated to the caller, then to the caller's caller, and so on, until\nthey reach the top-level interpreter, where they are reported to the\nuser accompanied by a stack traceback.\nFor C programmers, however, error checking always has to be explicit.\nAll functions in the Python/C API can raise exceptions, unless an\nexplicit claim is made otherwise in a function's documentation. In\ngeneral, when a function encounters an error, it sets an exception,\ndiscards any object references that it owns, and returns an\nerror indicator -- usually NULL or `-1`. A few functions\nreturn a Boolean true/false result, with false indicating an error.\nVery few functions return no explicit error indicator or have an\nambiguous return value, and require explicit testing for errors with\nPyErr_Occurred().\nException state is maintained in per-thread storage (this is\nequivalent to using global storage in an unthreaded application). A\nthread can be in one of two states: an exception has occurred, or not.\nThe function PyErr_Occurred() can be used to check for\nthis: it returns a borrowed reference to the exception type object\nwhen an exception has occurred, and NULL otherwise. There are a\nnumber of functions to set the exception state:\nPyErr_SetString()is the most\ncommon (though not the most general) function to set the exception\nstate, and PyErr_Clear()clears the\nexception state.\nThe full exception state consists of three objects (all of which can\nbe NULL): the exception type, the corresponding exception\nvalue, and the traceback. These have the same meanings as the Python\nobjects `sys.exc_type`, `sys.exc_value`, and\n`sys.exc_traceback`; however, they are not the same: the Python\nobjects represent the last exception being handled by a Python\ntry ... except statement, while the C level\nexception state only exists while an exception is being passed on\nbetween C functions until it reaches the Python bytecode interpreter's\nmain loop, which takes care of transferring it to `sys.exc_type`\nand friends.\nNote that starting with Python 1.5, the preferred, thread-safe way to\naccess the exception state from Python code is to call the function\nsys.exc_info(), which returns the per-thread exception state\nfor Python code. Also, the semantics of both ways to access the\nexception state have changed so that a function which catches an\nexception will save and restore its thread's exception state so as to\npreserve the exception state of its caller. This prevents common bugs\nin exception handling code caused by an innocent-looking function\noverwriting the exception being handled; it also reduces the often\nunwanted lifetime extension for objects that are referenced by the\nstack frames in the traceback.\nAs a general principle, a function that calls another function to\nperform some task should check whether the called function raised an\nexception, and if so, pass the exception state on to its caller. It\nshould discard any object references that it owns, and return an\nerror indicator, but it should not set another exception --\nthat would overwrite the exception that was just raised, and lose\nimportant information about the exact cause of the error.\nA simple example of detecting exceptions and passing them on is shown\nin the sum_sequence()example\nabove. It so happens that that example doesn't need to clean up any\nowned references when it detects an error. The following example\nfunction shows some error cleanup. First, to remind you why you like\nPython, we show the equivalent Python code:\n```text\n\ndef incr_item(dict, key):\ntry:\nitem = dict[key]\nexcept KeyError:\nitem = 0\ndict[key] = item + 1\n```\nHere is the corresponding C code, in all its glory:\n```text\n\nint incr_item(PyObject *dict, PyObject *key)\n{\n/* Objects all initialized to NULL for Py_XDECREF */\nPyObject *item = NULL, *const_one = NULL, *incremented_item = NULL;\nint rv = -1; /* Return value initialized to -1 (failure) */\n\nitem = PyObject_GetItem(dict, key);\nif (item == NULL) {\n/* Handle KeyError only: */\nif (!PyErr_ExceptionMatches(PyExc_KeyError))\ngoto error;\n\n/* Clear the error and use zero: */\nPyErr_Clear();\nitem = PyInt_FromLong(0L);\nif (item == NULL)\ngoto error;\n}\nconst_one = PyInt_FromLong(1L);\nif (const_one == NULL)\ngoto error;\n\nincremented_item = PyNumber_Add(item, const_one);\nif (incremented_item == NULL)\ngoto error;\n\nif (PyObject_SetItem(dict, key, incremented_item) < 0)\ngoto error;\nrv = 0; /* Success */\n/* Continue with cleanup code */\n\nerror:\n/* Cleanup code, shared by success and failure path */\n\n/* Use Py_XDECREF() to ignore NULL references */\nPy_XDECREF(item);\nPy_XDECREF(const_one);\nPy_XDECREF(incremented_item);\n\nreturn rv; /* -1 for error, 0 for success */\n}\n```\nThis example represents an endorsed use of the goto statement\nin C! It illustrates the use of\nPyErr_ExceptionMatches()and\nPyErr_Clear()to\nhandle specific exceptions, and the use of\nPy_XDECREF()to\ndispose of owned references that may be NULL (note the\n\"X\" in the name; Py_DECREF() would crash when\nconfronted with a NULL reference). It is important that the\nvariables used to hold owned references are initialized to NULL for\nthis to work; likewise, the proposed return value is initialized to\n`-1` (failure) and only set to success after the final call made\nis successful.", "python_version": "2.1", "length": 5496, "url": "https://docs.python.org/2.0/api/exceptions.html"}
{"title": "7.5.1 File Objects", "text": "otherObjects.html | otherObjects.html | instanceObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.5.1 File Objects\nPython's built-in file objects are implemented entirely on the\nFILE* support from the C standard library. This is an\nimplementation detail and may change in future releases of Python.", "python_version": "2.1", "length": 334, "url": "https://docs.python.org/2.0/api/fileObjects.html"}
{"title": "7.4.3 Floating Point Objects", "text": "longObjects.html | numericObjects.html | complexObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.4.3 Floating Point Objects", "python_version": "2.1", "length": 160, "url": "https://docs.python.org/2.0/api/floatObjects.html"}
{"title": "Front Matter", "text": "api.html | api.html | contents.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# Front Matter\nCopyright © 2001 Python Software Foundation.\nAll rights reserved.\nCopyright © 2000 BeOpen.com.\nAll rights reserved.\nCopyright © 1995-2000 Corporation for National Research Initiatives.\nAll rights reserved.\nCopyright © 1991-1995 Stichting Mathematisch Centrum.\nAll rights reserved.\nBEOPEN.COM TERMS AND CONDITIONS FOR PYTHON 2.0\nBEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1\n1. This LICENSE AGREEMENT is between BeOpen.com (``BeOpen''), having an\noffice at 160 Saratoga Avenue, Santa Clara, CA 95051, and the\nIndividual or Organization (``Licensee'') accessing and otherwise\nusing this software in source or binary form and its associated\ndocumentation (``the Software'').\n2. Subject to the terms and conditions of this BeOpen Python License\nAgreement, BeOpen hereby grants Licensee a non-exclusive,\nroyalty-free, world-wide license to reproduce, analyze, test, perform\nand/or display publicly, prepare derivative works, distribute, and\notherwise use the Software alone or in any derivative version,\nprovided, however, that the BeOpen Python License is retained in the\nSoftware, alone or in any derivative version prepared by Licensee.\n3. BeOpen is making the Software available to Licensee on an ``AS IS''\nbasis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR\nIMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND\nDISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS\nFOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT\nINFRINGE ANY THIRD PARTY RIGHTS.\n4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE\nSOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS\nAS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY\nDERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.\n5. This License Agreement will automatically terminate upon a material\nbreach of its terms and conditions.\n6. This License Agreement shall be governed by and interpreted in all\nrespects by the law of the State of California, excluding conflict of\nlaw provisions. Nothing in this License Agreement shall be deemed to\ncreate any relationship of agency, partnership, or joint venture\nbetween BeOpen and Licensee. This License Agreement does not grant\npermission to use BeOpen trademarks or trade names in a trademark\nsense to endorse or promote products or services of Licensee, or any\nthird party. As an exception, the ``BeOpen Python'' logos available\nat http://www.pythonlabs.com/logos.html may be used according to the\npermissions granted on that web page.\n7. By copying, installing or otherwise using the software, Licensee\nagrees to be bound by the terms and conditions of this License\nAgreement.\nCNRI OPEN SOURCE GPL-COMPATIBLE LICENSE AGREEMENT\nPython 1.6.1 is made available subject to the terms and conditions in\nCNRI's License Agreement. This Agreement together with Python 1.6.1 may\nbe located on the Internet using the following unique, persistent\nidentifier (known as a handle): 1895.22/1013. This Agreement may also\nbe obtained from a proxy server on the Internet using the following\nURL: http://hdl.handle.net/1895.22/1013.\nCWI PERMISSIONS STATEMENT AND DISCLAIMER\nCopyright © 1991 - 1995, Stichting Mathematisch Centrum\nAmsterdam, The Netherlands. All rights reserved.\nPermission to use, copy, modify, and distribute this software and its\ndocumentation for any purpose and without fee is hereby granted,\nprovided that the above copyright notice appear in all copies and that\nboth that copyright notice and this permission notice appear in\nsupporting documentation, and that the name of Stichting Mathematisch\nCentrum or CWI not be used in advertising or publicity pertaining to\ndistribution of the software without specific, written prior\npermission.\nSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO\nTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\nFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE\nFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\nWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\nACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\nOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n### Abstract:\nThis manual documents the API used by C and C++ programmers who\nwant to write extension modules or embed Python. It is a companion to\nExtending and Embedding the Python\nInterpreter (../ext/ext.html), which describes the general principles of extension\nwriting but does not document the API functions in detail.\nWarning: The current version of this document is incomplete.\nI hope that it is nevertheless useful. I will continue to work on it,\nand release new versions from time to time, independent from Python\nsource code releases.", "python_version": "2.1", "length": 4901, "url": "https://docs.python.org/2.0/api/front.html"}
{"title": "7.1 Fundamental Objects", "text": "concrete.html | concrete.html | typeObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 7.1 Fundamental Objects\nThis section describes Python type objects and the singleton object\n`None`.", "python_version": "2.1", "length": 218, "url": "https://docs.python.org/2.0/api/fundamental.html"}
{"title": "Index", "text": "reporting-bugs.html | api.html | about.html | Python/C API Reference Manual | contents.html\n---\n## Index\n---\n_ (#letter-_) |\na (#letter-a) |\nb (#letter-b) |\nc (#letter-c) |\nd (#letter-d) |\ne (#letter-e) |\nf (#letter-f) |\ng (#letter-g) |\nh (#letter-h) |\ni (#letter-i) |\nk (#letter-k) |\nl (#letter-l) |\nm (#letter-m) |\nn (#letter-n) |\no (#letter-o) |\np (#letter-p) |\nr (#letter-r) |\ns (#letter-s) |\nt (#letter-t) |\nu (#letter-u) |\nv (#letter-v)\n---\n## _ (underscore)\n---\n## A\n---\n## B\n---\n## C\n---\n## D\n---\n## E\n---\n## F\n---\n## G\n---\n## H\n---\n## I\n---\n## K\n---\n## L\n---\n## M\n---\n## N\n---\n## O\n---\n## P\n---\n## R\n---\n## S\n---\n## T\n---\n## U\n---\n## V", "python_version": "2.1", "length": 644, "url": "https://docs.python.org/2.0/api/genindex.html"}
{"title": "5.3 Importing Modules", "text": "processControl.html | utilities.html | abstract.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 5.3 Importing Modules", "python_version": "2.1", "length": 144, "url": "https://docs.python.org/2.0/api/importing.html"}
{"title": "1.1 Include Files", "text": "intro.html | intro.html | objects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 1.1 Include Files\nAll function, type and macro definitions needed to use the Python/C\nAPI are included in your code by the following line:\n```text\n\n#include \"Python.h\"\n```\nThis implies inclusion of the following standard headers:\n`<stdio.h>`, `<string.h>`, `<errno.h>`,\n`<limits.h>`, and `<stdlib.h>` (if available).\nAll user visible names defined by Python.h (except those defined by\nthe included standard headers) have one of the prefixes \"Py\" or\n\"_Py\". Names beginning with \"_Py\" are for internal use by\nthe Python implementation and should not be used by extension writers.\nStructure member names do not have a reserved prefix.\nImportant: user code should never define names that begin\nwith \"Py\" or \"_Py\". This confuses the reader, and\njeopardizes the portability of the user code to future Python\nversions, which may define additional names beginning with one of\nthese prefixes.\nThe header files are typically installed with Python. On Unix, these\nare located in the directories\nprefix/include/pythonversion/ and\nexec_prefix/include/pythonversion/, where\nprefix and exec_prefix are defined by the\ncorresponding parameters to Python's configure script and\nversion is `sys.version[:3]`. On Windows, the headers are\ninstalled in prefix/include, where prefix is\nthe installation directory specified to the installer.\nTo include the headers, place both directories (if different) on your\ncompiler's search path for includes. Do not place the parent\ndirectories on the search path and then use\n\"#include <python2.1/Python.h>\"; this will break on\nmulti-platform builds since the platform independent headers under\nprefix include the platform specific headers from\nexec_prefix.", "python_version": "2.1", "length": 1783, "url": "https://docs.python.org/2.0/api/includes.html"}
{"title": "Python/C API Reference Manual", "text": "../index.html | front.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# Python/C API Reference Manual\nGuido van Rossum\nFred L. Drake, Jr., editor\nPythonLabs\nE-mail: python-docs@python.org\nRelease 2.1\nApril 15, 2001", "python_version": "2.1", "length": 239, "url": "https://docs.python.org/2.0/api/index.html"}
{"title": "8. Initialization, Finalization, and Threads", "text": "cObjects.html | api.html | threads.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 8. Initialization, Finalization, and Threads", "python_version": "2.1", "length": 154, "url": "https://docs.python.org/2.0/api/initialization.html"}
{"title": "7.5.2 Instance Objects", "text": "fileObjects.html | otherObjects.html | moduleObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.5.2 Instance Objects\nThere are very few functions specific to instance objects.", "python_version": "2.1", "length": 210, "url": "https://docs.python.org/2.0/api/instanceObjects.html"}
{"title": "7.4.1 Plain Integer Objects", "text": "numericObjects.html | numericObjects.html | longObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.4.1 Plain Integer Objects", "python_version": "2.1", "length": 159, "url": "https://docs.python.org/2.0/api/intObjects.html"}
{"title": "1. Introduction", "text": "contents.html | api.html | includes.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 1. Introduction\nThe Application Programmer's Interface to Python gives C and\nC++ programmers access to the Python interpreter at a variety of\nlevels. The API is equally usable from C++, but for brevity it is\ngenerally referred to as the Python/C API. There are two\nfundamentally different reasons for using the Python/C API. The first\nreason is to write extension modules for specific purposes;\nthese are C modules that extend the Python interpreter. This is\nprobably the most common use. The second reason is to use Python as a\ncomponent in a larger application; this technique is generally\nreferred to as embedding Python in an application.\nWriting an extension module is a relatively well-understood process,\nwhere a ``cookbook'' approach works well. There are several tools\nthat automate the process to some extent. While people have embedded\nPython in other applications since its early existence, the process of\nembedding Python is less straightforward that writing an extension.\nMany API functions are useful independent of whether you're embedding\nor extending Python; moreover, most applications that embed Python\nwill need to provide a custom extension as well, so it's probably a\ngood idea to become familiar with writing an extension before\nattempting to embed Python in a real application.", "python_version": "2.1", "length": 1413, "url": "https://docs.python.org/2.0/api/intro.html"}
{"title": "7.2.5 List Objects", "text": "tupleObjects.html | sequenceObjects.html | mapObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.2.5 List Objects", "python_version": "2.1", "length": 148, "url": "https://docs.python.org/2.0/api/listObjects.html"}
{"title": "7.4.2 Long Integer Objects", "text": "intObjects.html | numericObjects.html | floatObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.4.2 Long Integer Objects", "python_version": "2.1", "length": 155, "url": "https://docs.python.org/2.0/api/longObjects.html"}
{"title": "7.3 Mapping Objects", "text": "listObjects.html | concrete.html | dictObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 7.3 Mapping Objects", "python_version": "2.1", "length": 141, "url": "https://docs.python.org/2.0/api/mapObjects.html"}
{"title": "10.2 Mapping Object Structures", "text": "common-structs.html | newTypes.html | number-structs.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 10.2 Mapping Object Structures", "python_version": "2.1", "length": 158, "url": "https://docs.python.org/2.0/api/mapping-structs.html"}
{"title": "6.4 Mapping Protocol", "text": "sequence.html | abstract.html | concrete.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 6.4 Mapping Protocol", "python_version": "2.1", "length": 136, "url": "https://docs.python.org/2.0/api/mapping.html"}
{"title": "9. Memory Management", "text": "threads.html | api.html | memoryOverview.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 9. Memory Management", "python_version": "2.1", "length": 136, "url": "https://docs.python.org/2.0/api/memory.html"}
{"title": "9.3 Examples", "text": "memoryInterface.html | memory.html | newTypes.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 9.3 Examples\nHere is the example from section 9.1 (memoryOverview.html#memoryOverview), rewritten so\nthat the I/O buffer is allocated from the Python heap by using the\nfirst function set:\n```text\n\nPyObject *res;\nchar *buf = (char *) PyMem_Malloc(BUFSIZ); /* for I/O */\n\nif (buf == NULL)\nreturn PyErr_NoMemory();\n/* ...Do some I/O operation involving buf... */\nres = PyString_FromString(buf);\nPyMem_Free(buf); /* allocated with PyMem_Malloc */\nreturn res;\n```\nThe same code using the type-oriented function set:\n```text\n\nPyObject *res;\nchar *buf = PyMem_New(char, BUFSIZ); /* for I/O */\n\nif (buf == NULL)\nreturn PyErr_NoMemory();\n/* ...Do some I/O operation involving buf... */\nres = PyString_FromString(buf);\nPyMem_Del(buf); /* allocated with PyMem_New */\nreturn res;\n```\nNote that in the two examples above, the buffer is always\nmanipulated via functions belonging to the same set. Indeed, it\nis required to use the same memory API family for a given\nmemory block, so that the risk of mixing different allocators is\nreduced to a minimum. The following code sequence contains two errors,\none of which is labeled as fatal because it mixes two different\nallocators operating on different heaps.\n```text\n\nchar *buf1 = PyMem_New(char, BUFSIZ);\nchar *buf2 = (char *) malloc(BUFSIZ);\nchar *buf3 = (char *) PyMem_Malloc(BUFSIZ);\n...\nPyMem_Del(buf3); /* Wrong -- should be PyMem_Free() */\nfree(buf2); /* Right -- allocated via malloc() */\nfree(buf1); /* Fatal -- should be PyMem_Del() */\n```\nIn addition to the functions aimed at handling raw memory blocks from\nthe Python heap, objects in Python are allocated and released with\nPyObject_New(), PyObject_NewVar() and\nPyObject_Del(), or with their corresponding macros\nPyObject_NEW(), PyObject_NEW_VAR() and\nPyObject_DEL().\nThese will be explained in the next chapter on defining and\nimplementing new object types in C.", "python_version": "2.1", "length": 1981, "url": "https://docs.python.org/2.0/api/memoryExamples.html"}
{"title": "9.2 Memory Interface", "text": "memoryOverview.html | memory.html | memoryExamples.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 9.2 Memory Interface\nThe following function sets, modeled after the ANSI C standard, are\navailable for allocating and releasing memory from the Python heap:\nThe following type-oriented macros are provided for convenience. Note\nthat TYPE refers to any C type.\nIn addition, the following macro sets are provided for calling the\nPython memory allocator directly, without involving the C API functions\nlisted above. However, note that their use does not preserve binary\ncompatibility accross Python versions and is therefore deprecated in\nextension modules.\nPyMem_MALLOC(), PyMem_REALLOC(), PyMem_FREE().\nPyMem_NEW(), PyMem_RESIZE(), PyMem_DEL().", "python_version": "2.1", "length": 768, "url": "https://docs.python.org/2.0/api/memoryInterface.html"}
{"title": "9.1 Overview", "text": "memory.html | memory.html | memoryInterface.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 9.1 Overview\nMemory management in Python involves a private heap containing all\nPython objects and data structures. The management of this private\nheap is ensured internally by the Python memory manager. The\nPython memory manager has different components which deal with various\ndynamic storage management aspects, like sharing, segmentation,\npreallocation or caching.\nAt the lowest level, a raw memory allocator ensures that there is\nenough room in the private heap for storing all Python-related data\nby interacting with the memory manager of the operating system. On top\nof the raw memory allocator, several object-specific allocators\noperate on the same heap and implement distinct memory management\npolicies adapted to the peculiarities of every object type. For\nexample, integer objects are managed differently within the heap than\nstrings, tuples or dictionaries because integers imply different\nstorage requirements and speed/space tradeoffs. The Python memory\nmanager thus delegates some of the work to the object-specific\nallocators, but ensures that the latter operate within the bounds of\nthe private heap.\nIt is important to understand that the management of the Python heap\nis performed by the interpreter itself and that the user has no\ncontrol on it, even if she regularly manipulates object pointers to\nmemory blocks inside that heap. The allocation of heap space for\nPython objects and other internal buffers is performed on demand by\nthe Python memory manager through the Python/C API functions listed in\nthis document.\nTo avoid memory corruption, extension writers should never try to\noperate on Python objects with the functions exported by the C\nlibrary: malloc(),\ncalloc(),\nrealloc()and\nfree(). This will result in\nmixed calls between the C allocator and the Python memory manager\nwith fatal consequences, because they implement different algorithms\nand operate on different heaps. However, one may safely allocate and\nrelease memory blocks with the C library allocator for individual\npurposes, as shown in the following example:\n```text\n\nPyObject *res;\nchar *buf = (char *) malloc(BUFSIZ); /* for I/O */\n\nif (buf == NULL)\nreturn PyErr_NoMemory();\n...Do some I/O operation involving buf...\nres = PyString_FromString(buf);\nfree(buf); /* malloc'ed */\nreturn res;\n```\nIn this example, the memory request for the I/O buffer is handled by\nthe C library allocator. The Python memory manager is involved only\nin the allocation of the string object returned as a result.\nIn most situations, however, it is recommended to allocate memory from\nthe Python heap specifically because the latter is under control of\nthe Python memory manager. For example, this is required when the\ninterpreter is extended with new object types written in C. Another\nreason for using the Python heap is the desire to inform the\nPython memory manager about the memory needs of the extension module.\nEven when the requested memory is used exclusively for internal,\nhighly-specific purposes, delegating all memory requests to the Python\nmemory manager causes the interpreter to have a more accurate image of\nits memory footprint as a whole. Consequently, under certain\ncircumstances, the Python memory manager may or may not trigger\nappropriate actions, like garbage collection, memory compaction or\nother preventive procedures. Note that by using the C library\nallocator as shown in the previous example, the allocated memory for\nthe I/O buffer escapes completely the Python memory manager.", "python_version": "2.1", "length": 3599, "url": "https://docs.python.org/2.0/api/memoryOverview.html"}
{"title": "7.5.3 Module Objects", "text": "instanceObjects.html | otherObjects.html | cObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.5.3 Module Objects\nThere are only a few functions special to module objects.", "python_version": "2.1", "length": 206, "url": "https://docs.python.org/2.0/api/moduleObjects.html"}
{"title": "10. Defining New Object Types", "text": "memoryExamples.html | api.html | common-structs.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 10. Defining New Object Types\nPyArg_ParseTupleAndKeywords, PyArg_ParseTuple, PyArg_Parse\nPy_BuildValue\nDL_IMPORT\n_Py_NoneStruct", "python_version": "2.1", "length": 250, "url": "https://docs.python.org/2.0/api/newTypes.html"}
{"title": "4.2 Deprecation of String Exceptions", "text": "standardExceptions.html | exceptionHandling.html | utilities.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 4.2 Deprecation of String Exceptions\nAll exceptions built into Python or provided in the standard library\nare derived from Exception.\nString exceptions are still supported in the interpreter to allow\nexisting code to run unmodified, but this will also change in a future\nrelease.", "python_version": "2.1", "length": 415, "url": "https://docs.python.org/2.0/api/node15.html"}
{"title": "7.4.4.1 Complex Numbers as C Structures", "text": "complexObjects.html | complexObjects.html | node45.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n### 7.4.4.1 Complex Numbers as C Structures\nNote that the functions which accept these structures as parameters\nand return them as results do so by value rather than\ndereferencing them through pointers. This is consistent throughout\nthe API.", "python_version": "2.1", "length": 365, "url": "https://docs.python.org/2.0/api/node44.html"}
{"title": "7.4.4.2 Complex Numbers as Python Objects", "text": "node44.html | complexObjects.html | otherObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n### 7.4.4.2 Complex Numbers as Python Objects", "python_version": "2.1", "length": 167, "url": "https://docs.python.org/2.0/api/node45.html"}
{"title": "7.1.2 The None Object", "text": "typeObjects.html | fundamental.html | sequenceObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.1.2 The None Object\nNote that the PyTypeObject for `None` is not directly\nexposed in the Python/C API. Since `None` is a singleton,\ntesting for object identity (using \"==\" in C) is sufficient.\nThere is no PyNone_Check() function for the same reason.", "python_version": "2.1", "length": 381, "url": "https://docs.python.org/2.0/api/noneObject.html"}
{"title": "10.3 Number Object Structures", "text": "mapping-structs.html | newTypes.html | sequence-structs.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 10.3 Number Object Structures", "python_version": "2.1", "length": 160, "url": "https://docs.python.org/2.0/api/number-structs.html"}
{"title": "6.2 Number Protocol", "text": "object.html | abstract.html | sequence.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 6.2 Number Protocol", "python_version": "2.1", "length": 133, "url": "https://docs.python.org/2.0/api/number.html"}
{"title": "7.4 Numeric Objects", "text": "dictObjects.html | concrete.html | intObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 7.4 Numeric Objects", "python_version": "2.1", "length": 140, "url": "https://docs.python.org/2.0/api/numericObjects.html"}
{"title": "6.1 Object Protocol", "text": "abstract.html | abstract.html | number.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 6.1 Object Protocol\nSubclass determination is done in a fairly straightforward way, but\nincludes a wrinkle that implementors of extensions to the class system\nmay want to be aware of. If A and B are class\nobjects, B is a subclass of A if it inherits from\nA either directly or indirectly. If either is not a class\nobject, a more general mechanism is used to determine the class\nrelationship of the two objects. When testing if B is a\nsubclass of A, if A is B,\nPyObject_IsSubclass() returns true. If A and\nB are different objects, B's __bases__ attribute\nis searched in a depth-first fashion for A -- the presence of\nthe __bases__ attribute is considered sufficient for this\ndetermination.", "python_version": "2.1", "length": 801, "url": "https://docs.python.org/2.0/api/object.html"}
{"title": "1.2 Objects, Types and Reference Counts", "text": "includes.html | intro.html | refcounts.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 1.2 Objects, Types and Reference Counts\nMost Python/C API functions have one or more arguments as well as a\nreturn value of type PyObject*. This type is a pointer\nto an opaque data type representing an arbitrary Python\nobject. Since all Python object types are treated the same way by the\nPython language in most situations (e.g., assignments, scope rules,\nand argument passing), it is only fitting that they should be\nrepresented by a single C type. Almost all Python objects live on the\nheap: you never declare an automatic or static variable of type\nPyObject, only pointer variables of type PyObject* can\nbe declared. The sole exception are the type objects;\nsince these must never be deallocated, they are typically static\nPyTypeObject objects.\nAll Python objects (even Python integers) have a type and a\nreference count. An object's type determines what kind of object\nit is (e.g., an integer, a list, or a user-defined function; there are\nmany more as explained in the Python\nReference Manual (../ref/ref.html)). For each of the well-known types there is a macro\nto check whether an object is of that type; for instance,\n\"PyList_Check(a)\" is true if (and only if) the object\npointed to by a is a Python list.", "python_version": "2.1", "length": 1328, "url": "https://docs.python.org/2.0/api/objects.html"}
{"title": "5.1 OS Utilities", "text": "utilities.html | utilities.html | processControl.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 5.1 OS Utilities", "python_version": "2.1", "length": 140, "url": "https://docs.python.org/2.0/api/os.html"}
{"title": "7.5 Other Objects", "text": "node45.html | concrete.html | fileObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 7.5 Other Objects", "python_version": "2.1", "length": 134, "url": "https://docs.python.org/2.0/api/otherObjects.html"}
{"title": "5.2 Process Control", "text": "os.html | utilities.html | importing.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 5.2 Process Control", "python_version": "2.1", "length": 131, "url": "https://docs.python.org/2.0/api/processControl.html"}
{"title": "1.2.1.1 Reference Count Details", "text": "refcounts.html | refcounts.html | types.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n### 1.2.1.1 Reference Count Details\nThe reference count behavior of functions in the Python/C API is best\nexplained in terms of ownership of references. Note that we\ntalk of owning references, never of owning objects; objects are always\nshared! When a function owns a reference, it has to dispose of it\nproperly -- either by passing ownership on (usually to its caller) or\nby calling Py_DECREF() or Py_XDECREF(). When\na function passes ownership of a reference on to its caller, the\ncaller is said to receive a new reference. When no ownership\nis transferred, the caller is said to borrow the reference.\nNothing needs to be done for a borrowed reference.\nConversely, when a calling function passes it a reference to an\nobject, there are two possibilities: the function steals a\nreference to the object, or it does not. Few functions steal\nreferences; the two notable exceptions are\nPyList_SetItem()and\nPyTuple_SetItem(), which\nsteal a reference to the item (but not to the tuple or list into which\nthe item is put!). These functions were designed to steal a reference\nbecause of a common idiom for populating a tuple or list with newly\ncreated objects; for example, the code to create the tuple `(1,\n2, \"three\")` could look like this (forgetting about error handling for\nthe moment; a better way to code this is shown below):\n```text\n\nPyObject *t;\n\nt = PyTuple_New(3);\nPyTuple_SetItem(t, 0, PyInt_FromLong(1L));\nPyTuple_SetItem(t, 1, PyInt_FromLong(2L));\nPyTuple_SetItem(t, 2, PyString_FromString(\"three\"));\n```\nIncidentally, PyTuple_SetItem() is the only way to\nset tuple items; PySequence_SetItem() and\nPyObject_SetItem() refuse to do this since tuples are an\nimmutable data type. You should only use\nPyTuple_SetItem() for tuples that you are creating\nyourself.\nEquivalent code for populating a list can be written using\nPyList_New() and PyList_SetItem(). Such code\ncan also use PySequence_SetItem(); this illustrates the\ndifference between the two (the extra Py_DECREF() calls):\n```text\n\nPyObject *l, *x;\n\nl = PyList_New(3);\nx = PyInt_FromLong(1L);\nPySequence_SetItem(l, 0, x); Py_DECREF(x);\nx = PyInt_FromLong(2L);\nPySequence_SetItem(l, 1, x); Py_DECREF(x);\nx = PyString_FromString(\"three\");\nPySequence_SetItem(l, 2, x); Py_DECREF(x);\n```\nYou might find it strange that the ``recommended'' approach takes more\ncode. However, in practice, you will rarely use these ways of\ncreating and populating a tuple or list. There's a generic function,\nPy_BuildValue(), that can create most common objects from\nC values, directed by a format string. For example, the\nabove two blocks of code could be replaced by the following (which\nalso takes care of the error checking):\n```text\n\nPyObject *t, *l;\n\nt = Py_BuildValue(\"(iis)\", 1, 2, \"three\");\nl = Py_BuildValue(\"[iis]\", 1, 2, \"three\");\n```\nIt is much more common to use PyObject_SetItem() and\nfriends with items whose references you are only borrowing, like\narguments that were passed in to the function you are writing. In\nthat case, their behaviour regarding reference counts is much saner,\nsince you don't have to increment a reference count so you can give a\nreference away (``have it be stolen''). For example, this function\nsets all items of a list (actually, any mutable sequence) to a given\nitem:\n```text\n\nint set_all(PyObject *target, PyObject *item)\n{\nint i, n;\n\nn = PyObject_Length(target);\nif (n < 0)\nreturn -1;\nfor (i = 0; i < n; i++) {\nif (PyObject_SetItem(target, i, item) < 0)\nreturn -1;\n}\nreturn 0;\n}\n```\nThe situation is slightly different for function return values.\nWhile passing a reference to most functions does not change your\nownership responsibilities for that reference, many functions that\nreturn a referece to an object give you ownership of the reference.\nThe reason is simple: in many cases, the returned object is created\non the fly, and the reference you get is the only reference to the\nobject. Therefore, the generic functions that return object\nreferences, like PyObject_GetItem() and\nPySequence_GetItem(), always return a new reference (i.e.,\nthe caller becomes the owner of the reference).\nIt is important to realize that whether you own a reference returned\nby a function depends on which function you call only -- the\nplumage (i.e., the type of the type of the object passed as an\nargument to the function) doesn't enter into it! Thus, if you\nextract an item from a list using PyList_GetItem(), you\ndon't own the reference -- but if you obtain the same item from the\nsame list using PySequence_GetItem() (which happens to\ntake exactly the same arguments), you do own a reference to the\nreturned object.\nHere is an example of how you could write a function that computes the\nsum of the items in a list of integers; once using\nPyList_GetItem(), and once using\nPySequence_GetItem().\n```text\n\nlong sum_list(PyObject *list)\n{\nint i, n;\nlong total = 0;\nPyObject *item;\n\nn = PyList_Size(list);\nif (n < 0)\nreturn -1; /* Not a list */\nfor (i = 0; i < n; i++) {\nitem = PyList_GetItem(list, i); /* Can't fail */\nif (!PyInt_Check(item)) continue; /* Skip non-integers */\ntotal += PyInt_AsLong(item);\n}\nreturn total;\n}\n```\n```text\n\nlong sum_sequence(PyObject *sequence)\n{\nint i, n;\nlong total = 0;\nPyObject *item;\nn = PySequence_Length(sequence);\nif (n < 0)\nreturn -1; /* Has no length */\nfor (i = 0; i < n; i++) {\nitem = PySequence_GetItem(sequence, i);\nif (item == NULL)\nreturn -1; /* Not a sequence, or other failure */\nif (PyInt_Check(item))\ntotal += PyInt_AsLong(item);\nPy_DECREF(item); /* Discard reference ownership */\n}\nreturn total;\n}\n```", "python_version": "2.1", "length": 5630, "url": "https://docs.python.org/2.0/api/refcountDetails.html"}
{"title": "1.2.1 Reference Counts", "text": "objects.html | objects.html | refcountDetails.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 1.2.1 Reference Counts\nThe reference count is important because today's computers have a\nfinite (and often severely limited) memory size; it counts how many\ndifferent places there are that have a reference to an object. Such a\nplace could be another object, or a global (or static) C variable, or\na local variable in some C function. When an object's reference count\nbecomes zero, the object is deallocated. If it contains references to\nother objects, their reference count is decremented. Those other\nobjects may be deallocated in turn, if this decrement makes their\nreference count become zero, and so on. (There's an obvious problem\nwith objects that reference each other here; for now, the solution is\n``don't do that.'')\nReference counts are always manipulated explicitly. The normal way is\nto use the macro Py_INCREF()to\nincrement an object's reference count by one, and\nPy_DECREF()to decrement it by\none. The Py_DECREF() macro is considerably more complex\nthan the incref one, since it must check whether the reference count\nbecomes zero and then cause the object's deallocator to be called.\nThe deallocator is a function pointer contained in the object's type\nstructure. The type-specific deallocator takes care of decrementing\nthe reference counts for other objects contained in the object if this\nis a compound object type, such as a list, as well as performing any\nadditional finalization that's needed. There's no chance that the\nreference count can overflow; at least as many bits are used to hold\nthe reference count as there are distinct memory locations in virtual\nmemory (assuming `sizeof(long) >= sizeof(char*)`). Thus, the\nreference count increment is a simple operation.\nIt is not necessary to increment an object's reference count for every\nlocal variable that contains a pointer to an object. In theory, the\nobject's reference count goes up by one when the variable is made to\npoint to it and it goes down by one when the variable goes out of\nscope. However, these two cancel each other out, so at the end the\nreference count hasn't changed. The only real reason to use the\nreference count is to prevent the object from being deallocated as\nlong as our variable is pointing to it. If we know that there is at\nleast one other reference to the object that lives at least as long as\nour variable, there is no need to increment the reference count\ntemporarily. An important situation where this arises is in objects\nthat are passed as arguments to C functions in an extension module\nthat are called from Python; the call mechanism guarantees to hold a\nreference to every argument for the duration of the call.\nHowever, a common pitfall is to extract an object from a list and\nhold on to it for a while without incrementing its reference count.\nSome other operation might conceivably remove the object from the\nlist, decrementing its reference count and possible deallocating it.\nThe real danger is that innocent-looking operations may invoke\narbitrary Python code which could do this; there is a code path which\nallows control to flow back to the user from a Py_DECREF(),\nso almost any operation is potentially dangerous.\nA safe approach is to always use the generic operations (functions\nwhose name begins with \"PyObject_\", \"PyNumber_\",\n\"PySequence_\" or \"PyMapping_\"). These operations always\nincrement the reference count of the object they return. This leaves\nthe caller with the responsibility to call\nPy_DECREF() when they are done with the result; this soon\nbecomes second nature.", "python_version": "2.1", "length": 3626, "url": "https://docs.python.org/2.0/api/refcounts.html"}
{"title": "A. Reporting Bugs", "text": "example-cycle-support.html | api.html | genindex.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# A. Reporting Bugs\nPython is a mature programming language which has established a\nreputation for stability. In order to maintain this reputation, the\ndevelopers would like to know of any deficiencies you find in Python\nor its documentation.\nAll bug reports should be submitted via the Python Bug Tracker on\nSourceForge (http://sourceforge.net/bugs/?group_id=5470). The\nbug tracker offers a Web form which allows pertinent information to be\nentered and submitted to the developers.\nBefore submitting a report, please log into SourceForge if you are a\nmember; this will make it possible for the developers to contact you\nfor additional information if needed. If you are not a SourceForge\nmember but would not mind the developers contacting you, you may\ninclude your email address in your bug description. In this case,\nplease realize that the information is publically available and cannot\nbe protected.\nThe first step in filing a report is to determine whether the problem\nhas already been reported. The advantage in doing so, aside from\nsaving the developers time, is that you learn what has been done to\nfix it; it may be that the problem has already been fixed for the next\nrelease, or additional information is needed (in which case you are\nwelcome to provide it if you can!). To do this, search the bug\ndatabase using the search box near the bottom of the page.\nIf the problem you're reporting is not already in the bug tracker, go\nback to the Python Bug Tracker\n(http://sourceforge.net/bugs/?group_id=5470). Select the\n``Submit a Bug'' link at the top of the page to open the bug reporting\nform.\nThe submission form has a number of fields. The only fields that are\nrequired are the ``Summary'' and ``Details'' fields. For the summary,\nenter a very short description of the problem; less than ten\nwords is good. In the Details field, describe the problem in detail,\nincluding what you expected to happen and what did happen. Be sure to\ninclude the version of Python you used, whether any extension modules\nwere involved, and what hardware and software platform you were using\n(including version information as appropriate).\nThe only other field that you may want to set is the ``Category''\nfield, which allows you to place the bug report into a broad category\n(such as ``Documentation'' or ``Library'').\nEach bug report will be assigned to a developer who will determine\nwhat needs to be done to correct the problem. If you have a\nSourceForge account and logged in to report the problem, you will\nreceive an update each time action is taken on the bug.\nSee Also:", "python_version": "2.1", "length": 2690, "url": "https://docs.python.org/2.0/api/reporting-bugs.html"}
{"title": "10.4 Sequence Object Structures", "text": "number-structs.html | newTypes.html | buffer-structs.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 10.4 Sequence Object Structures", "python_version": "2.1", "length": 159, "url": "https://docs.python.org/2.0/api/sequence-structs.html"}
{"title": "6.3 Sequence Protocol", "text": "number.html | abstract.html | mapping.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 6.3 Sequence Protocol", "python_version": "2.1", "length": 134, "url": "https://docs.python.org/2.0/api/sequence.html"}
{"title": "7.2 Sequence Objects", "text": "noneObject.html | concrete.html | stringObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 7.2 Sequence Objects\nGeneric operations on sequence objects were discussed in the previous\nchapter; this section deals with the specific kinds of sequence\nobjects that are intrinsic to the Python language.", "python_version": "2.1", "length": 328, "url": "https://docs.python.org/2.0/api/sequenceObjects.html"}
{"title": "4.1 Standard Exceptions", "text": "exceptionHandling.html | exceptionHandling.html | node15.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 4.1 Standard Exceptions\nAll standard Python exceptions are available as global variables whose\nnames are \"PyExc_\" followed by the Python exception name. These\nhave the type PyObject*; they are all class objects. For\ncompleteness, here are all the variables:\nNotes:\n(1): This is a base class for other standard exceptions.\n(2): Only defined on Windows; protect code that uses this by testing that\nthe preprocessor macro `MS_WINDOWS` is defined.", "python_version": "2.1", "length": 575, "url": "https://docs.python.org/2.0/api/standardExceptions.html"}
{"title": "7.2.1 String Objects", "text": "sequenceObjects.html | sequenceObjects.html | unicodeObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.2.1 String Objects\nThese functions raise TypeError when expecting a string\nparameter and are called with a non-string parameter.", "python_version": "2.1", "length": 267, "url": "https://docs.python.org/2.0/api/stringObjects.html"}
{"title": "10.6 Supporting Cyclic Garbarge Collection", "text": "buffer-structs.html | newTypes.html | example-cycle-support.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 10.6 Supporting Cyclic Garbarge Collection\nPython's support for detecting and collecting garbage which involves\ncircular references requires support from object types which are\n``containers'' for other objects which may also be containers. Types\nwhich do not store references to other objects, or which only store\nreferences to atomic types (such as numbers or strings), do not need\nto provide any explicit support for garbage collection.\nTo create a container type, the tp_flags field of the type\nobject must include the Py_TPFLAGS_GC and provide an\nimplementation of the tp_traverse handler. The computed\nvalue of the tp_basicsize field must include\nPyGC_HEAD_SIZE as well. If instances of the type are\nmutable, a tp_clear implementation must also be provided.\nConstructors for container types must conform to two rules:\n1. The memory for the object must be allocated using\nPyObject_New() or PyObject_VarNew().\n2. Once all the fields which may contain references to other\ncontainers are initialized, it must call\nPyObject_GC_Init().\nSimilarly, the deallocator for the object must conform to a similar\npair of rules:\n1. Before fields which refer to other containers are invalidated,\nPyObject_GC_Fini() must be called.\n2. The object's memory must be deallocated using\nPyObject_Del().\nThe tp_traverse handler accepts a function parameter of this\ntype:\nThe tp_traverse handler must have the following type:\nThe tp_clear handler must be of the inquiry type, or\nNULL if the object is immutable.", "python_version": "2.1", "length": 1625, "url": "https://docs.python.org/2.0/api/supporting-cycle-detection.html"}
{"title": "8.1 Thread State and the Global Interpreter Lock", "text": "initialization.html | initialization.html | memory.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 8.1 Thread State and the Global Interpreter Lock\nThe Python interpreter is not fully thread safe. In order to support\nmulti-threaded Python programs, there's a global lock that must be\nheld by the current thread before it can safely access Python objects.\nWithout the lock, even the simplest operations could cause problems in\na multi-threaded program: for example, when two threads simultaneously\nincrement the reference count of the same object, the reference count\ncould end up being incremented only once instead of twice.\nTherefore, the rule exists that only the thread that has acquired the\nglobal interpreter lock may operate on Python objects or call Python/C\nAPI functions. In order to support multi-threaded Python programs,\nthe interpreter regularly releases and reacquires the lock -- by\ndefault, every ten bytecode instructions (this can be changed with\nsys.setcheckinterval()). The lock is also released and\nreacquired around potentially blocking I/O operations like reading or\nwriting a file, so that other threads can run while the thread that\nrequests the I/O is waiting for the I/O operation to complete.\nThe Python interpreter needs to keep some bookkeeping information\nseparate per thread -- for this it uses a data structure called\nPyThreadState. This is new in Python\n1.5; in earlier versions, such state was stored in global variables,\nand switching threads could cause problems. In particular, exception\nhandling is now thread safe, when the application uses\nsys.exc_info() to access the exception last raised in the\ncurrent thread.\nThere's one global variable left, however: the pointer to the current\nPyThreadStatestructure. While most\nthread packages have a way to store ``per-thread global data,''\nPython's internal platform independent thread abstraction doesn't\nsupport this yet. Therefore, the current thread state must be\nmanipulated explicitly.\nThis is easy enough in most cases. Most code manipulating the global\ninterpreter lock has the following simple structure:\n```text\n\nSave the thread state in a local variable.\nRelease the interpreter lock.\n...Do some blocking I/O operation...\nReacquire the interpreter lock.\nRestore the thread state from the local variable.\n```\nThis is so common that a pair of macros exists to simplify it:\n```text\n\nPy_BEGIN_ALLOW_THREADS\n...Do some blocking I/O operation...\nPy_END_ALLOW_THREADS\n```\nThe `Py_BEGIN_ALLOW_THREADS`macro\nopens a new block and declares a hidden local variable; the\n`Py_END_ALLOW_THREADS`macro closes\nthe block. Another advantage of using these two macros is that when\nPython is compiled without thread support, they are defined empty,\nthus saving the thread state and lock manipulations.\nWhen thread support is enabled, the block above expands to the\nfollowing code:\n```text\n\nPyThreadState *_save;\n\n_save = PyEval_SaveThread();\n...Do some blocking I/O operation...\nPyEval_RestoreThread(_save);\n```\nUsing even lower level primitives, we can get roughly the same effect\nas follows:\n```text\n\nPyThreadState *_save;\n\n_save = PyThreadState_Swap(NULL);\nPyEval_ReleaseLock();\n...Do some blocking I/O operation...\nPyEval_AcquireLock();\nPyThreadState_Swap(_save);\n```\nThere are some subtle differences; in particular,\nPyEval_RestoreThread()saves\nand restores the value of the global variable\nerrno, since the lock manipulation does not\nguarantee that errno is left alone. Also, when thread support\nis disabled,\nPyEval_SaveThread()and\nPyEval_RestoreThread() don't manipulate the lock; in this\ncase, PyEval_ReleaseLock()and\nPyEval_AcquireLock()are not\navailable. This is done so that dynamically loaded extensions\ncompiled with thread support enabled can be loaded by an interpreter\nthat was compiled with disabled thread support.\nThe global interpreter lock is used to protect the pointer to the\ncurrent thread state. When releasing the lock and saving the thread\nstate, the current thread state pointer must be retrieved before the\nlock is released (since another thread could immediately acquire the\nlock and store its own thread state in the global variable).\nConversely, when acquiring the lock and restoring the thread state,\nthe lock must be acquired before storing the thread state pointer.\nWhy am I going on with so much detail about this? Because when\nthreads are created from C, they don't have the global interpreter\nlock, nor is there a thread state data structure for them. Such\nthreads must bootstrap themselves into existence, by first creating a\nthread state data structure, then acquiring the lock, and finally\nstoring their thread state pointer, before they can start using the\nPython/C API. When they are done, they should reset the thread state\npointer, release the lock, and finally free their thread state data\nstructure.\nWhen creating a thread data structure, you need to provide an\ninterpreter state data structure. The interpreter state data\nstructure hold global data that is shared by all threads in an\ninterpreter, for example the module administration\n(`sys.modules`). Depending on your needs, you can either create\na new interpreter state data structure, or share the interpreter state\ndata structure used by the Python main thread (to access the latter,\nyou must obtain the thread state and access its interp member;\nthis must be done by a thread that is created by Python or by the main\nthread after Python is initialized).\nThe following macros are normally used without a trailing semicolon;\nlook for example usage in the Python source distribution.\nAll of the following functions are only available when thread support\nis enabled at compile time, and must be called only when the\ninterpreter lock has been created.", "python_version": "2.1", "length": 5754, "url": "https://docs.python.org/2.0/api/threads.html"}
{"title": "7.2.4 Tuple Objects", "text": "bufferObjects.html | sequenceObjects.html | listObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.2.4 Tuple Objects", "python_version": "2.1", "length": 151, "url": "https://docs.python.org/2.0/api/tupleObjects.html"}
{"title": "7.1.1 Type Objects", "text": "fundamental.html | fundamental.html | noneObject.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.1.1 Type Objects", "python_version": "2.1", "length": 143, "url": "https://docs.python.org/2.0/api/typeObjects.html"}
{"title": "1.2.2 Types", "text": "refcountDetails.html | objects.html | exceptions.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 1.2.2 Types\nThere are few other data types that play a significant role in\nthe Python/C API; most are simple C types such as int,\nlong, double and char*. A few structure types\nare used to describe static tables used to list the functions exported\nby a module or the data attributes of a new object type, and another\nis used to describe the value of a complex number. These will\nbe discussed together with the functions that use them.", "python_version": "2.1", "length": 558, "url": "https://docs.python.org/2.0/api/types.html"}
{"title": "7.2.2.2 Methods and Slot Functions", "text": "builtinCodecs.html | unicodeObjects.html | bufferObjects.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n### 7.2.2.2 Methods and Slot Functions\nThe following APIs are capable of handling Unicode objects and strings\non input (we refer to them as strings in the descriptions) and return\nUnicode objects or integers as apporpriate.\nThey all return NULL or -1 in case an exception occurrs.", "python_version": "2.1", "length": 410, "url": "https://docs.python.org/2.0/api/unicodeMethodsAndSlots.html"}
{"title": "7.2.2 Unicode Objects", "text": "stringObjects.html | sequenceObjects.html | builtinCodecs.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n## 7.2.2 Unicode Objects\nThese are the basic Unicode object types used for the Unicode\nimplementation in Python:\nThe following APIs are really C macros and can be used to do fast\nchecks and to access internal read-only data of Unicode objects:\nUnicode provides many different character properties. The most often\nneeded ones are available through these macros which are mapped to C\nfunctions depending on the Python configuration.\nThese APIs can be used for fast direct character conversions:\nTo create Unicode objects and access their basic sequence properties,\nuse these APIs:\nIf the platform supports wchar_t and provides a header file\nwchar.h, Python can interface directly to this type using the\nfollowing functions. Support is optimized if Python's own\nPy_UNICODE type is identical to the system's wchar_t.", "python_version": "2.1", "length": 943, "url": "https://docs.python.org/2.0/api/unicodeObjects.html"}
{"title": "5. Utilities", "text": "node15.html | api.html | os.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 5. Utilities\nThe functions in this chapter perform various utility tasks, such as\nparsing function arguments and constructing Python values from C\nvalues.", "python_version": "2.1", "length": 257, "url": "https://docs.python.org/2.0/api/utilities.html"}
{"title": "2. The Very High Level Layer", "text": "embedding.html | api.html | countingRefs.html | Python/C API Reference Manual | contents.html | genindex.html\n---\n# 2. The Very High Level Layer\nThe functions in this chapter will let you execute Python source code\ngiven in a file or a buffer, but they will not let you interact in a\nmore detailed way with the interpreter.\nSeveral of these functions accept a start symbol from the grammar as a\nparameter. The available start symbols are Py_eval_input,\nPy_file_input, and Py_single_input. These are\ndescribed following the functions which accept them as parameters.\nNote also that several of these functions take FILE*\nparameters. On particular issue which needs to be handled carefully\nis that the FILE structure for different C libraries can be\ndifferent and incompatible. Under Windows (at least), it is possible\nfor dynamically linked extensions to actually use different libraries,\nso care should be taken that FILE* parameters are only passed\nto these functions if it is certain that they were created by the same\nlibrary that the Python runtime is using.", "python_version": "2.1", "length": 1061, "url": "https://docs.python.org/2.0/api/veryhigh.html"}
{"title": "About this document ...", "text": "sdist-cmd.html | dist.html | Distributing Python Modules\n---\n# About this document ...\nDistributing Python Modules\nThis document was generated using the LaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) translator.\nLaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) is Copyright ©\n1993, 1994, 1995, 1996, 1997, Nikos\nDrakos (http://cbl.leeds.ac.uk/nikos/personal.html), Computer Based Learning Unit, University of\nLeeds, and Copyright © 1997, 1998, Ross\nMoore (http://www.maths.mq.edu.au/~ross/), Mathematics Department, Macquarie University,\nSydney.\nThe application of LaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) to the Python\ndocumentation has been heavily tailored by Fred L. Drake,\nJr. Original navigation icons were contributed by Christopher\nPetrilli.\n---\n## Comments and Questions\nGeneral comments and questions regarding this document should\nbe sent by email to python-docs@python.org (mailto:python-docs@python.org). If you find specific errors in\nthis document, please report the bug at the Python Bug\nTracker (http://sourceforge.net/bugs/?group_id=5470) at SourceForge (http://sourceforge.net/).\nQuestions regarding how to use the information in this\ndocument should be sent to the Python news group, comp.lang.python (news:comp.lang.python), or the Python mailing list (http://www.python.org/mailman/listinfo/python-list) (which is gated to the newsgroup and\ncarries the same content).\nFor any of these channels, please be sure not to send HTML email.\nThanks.\n---\nsdist-cmd.html | dist.html | Distributing Python Modules\n---", "python_version": "2.1", "length": 1568, "url": "https://docs.python.org/2.0/dist/bdist-cmds.html"}
{"title": "6 Creating Built Distributions", "text": "source-dist.html | dist.html | sdist-cmd.html | Distributing Python Modules\n---\n- 6.1 Creating dumb built distributions (creating-wininst.html#SECTION000610000000000000000)\n 6.2 Creating RPM packages (creating-wininst.html#SECTION000620000000000000000)\n 6.3 Creating Windows installers (creating-wininst.html#SECTION000630000000000000000)\n---\n# 6 Creating Built Distributions\nA ``built distribution'' is what you're probably used to thinking of\neither as a ``binary package'' or an ``installer'' (depending on your\nbackground). It's not necessarily binary, though, because it might\ncontain only Python source code and/or byte-code; and we don't call it a\npackage, because that word is already spoken for in Python. (And\n``installer'' is a term specific to the Windows world. ** do Mac\npeople use it? **)\nA built distribution is how you make life as easy as possible for\ninstallers of your module distribution: for users of RPM-based Linux\nsystems, it's a binary RPM; for Windows users, it's an executable\ninstaller; for Debian-based Linux users, it's a Debian package; and so\nforth. Obviously, no one person will be able to create built\ndistributions for every platform under the sun, so the Distutils are\ndesigned to enable module developers to concentrate on their\nspecialty--writing code and creating source distributions--while an\nintermediary species of packager springs up to turn source\ndistributions into built distributions for as many platforms as there\nare packagers.\nOf course, the module developer could be his own packager; or the\npackager could be a volunteer ``out there'' somewhere who has access to\na platform which the original developer does not; or it could be\nsoftware periodically grabbing new source distributions and turning them\ninto built distributions for as many platforms as the software has\naccess to. Regardless of the nature of the beast, a packager uses the\nsetup script and the `bdist` command family to generate built\ndistributions.\nAs a simple example, if I run the following command in the Distutils\nsource tree:\n```text\n\npython setup.py bdist\n```\nthen the Distutils builds my module distribution (the Distutils itself\nin this case), does a ``fake'' installation (also in the build\ndirectory), and creates the default type of built distribution for my\nplatform. The default format for built distributions is a ``dumb'' tar\nfile on Unix, and an simple executable installer on Windows. (That tar\nfile is considered ``dumb'' because it has to be unpacked in a specific\nlocation to work.)\nThus, the above command on a Unix system creates\nDistutils-0.9.1.plat.tar.gz; unpacking this tarball\nfrom the right place installs the Distutils just as though you had\ndownloaded the source distribution and run `python setup.py\ninstall`. (The ``right place'' is either the root of the filesystem or\nPython's prefix directory, depending on the options given to\nthe `bdist_dumb` command; the default is to make dumb\ndistributions relative to prefix.)\nObviously, for pure Python distributions, this isn't a huge win--but\nfor non-pure distributions, which include extensions that would need to\nbe compiled, it can mean the difference between someone being able to\nuse your extensions or not. And creating ``smart'' built distributions,\nsuch as an RPM package or an executable installer for Windows, is a big\nwin for users even if your distribution doesn't include any extensions.\nThe `bdist` command has a --formats option,\nsimilar to the `sdist` command, which you can use to select the\ntypes of built distribution to generate: for example,\n```text\n\npython setup.py bdist --format=zip\n```\nwould, when run on a Unix system, create\nDistutils-0.8.plat.zip--again, this archive would be\nunpacked from the root directory to install the Distutils.\nThe available formats for built distributions are:\nNotes:\n(1): default on Unix\n(2): default on Windows ** to-do! **\n(3): requires external utilities: tar and possibly one\nof gzip, bzip2, or compress\n(4): requires either external zip utility or\nzipfile module (not part of the standard Python library)\n(5): requires external rpm utility, version 3.0.4 or\nbetter (use `rpm -version` to find out which version you have)\nYou don't have to use the `bdist` command with the\n--formats option; you can also use the command that\ndirectly implements the format you're interested in. Some of these\n`bdist` ``sub-commands'' actually generate several similar\nformats; for instance, the `bdist_dumb` command generates all\nthe ``dumb'' archive formats (`tar`, `ztar`, `gztar`, and\n`zip`), and `bdist_rpm` generates both binary and source\nRPMs. The `bdist` sub-commands, and the formats generated by\neach, are:\nThe following sections give details on the individual `bdist_*`\ncommands.\n## 6.1 Creating dumb built distributions\n** Need to document absolute vs. prefix-relative packages here, but\nfirst I have to implement it! **\n## 6.2 Creating RPM packages\nThe RPM format is used by many of popular Linux distributions, including\nRed Hat, SuSE, and Mandrake. If one of these (or any of the other\nRPM-based Linux distributions) is your usual environment, creating RPM\npackages for other users of that same distribution is trivial.\nDepending on the complexity of your module distribution and differences\nbetween Linux distributions, you may also be able to create RPMs that\nwork on different RPM-based distributions.\nThe usual way to create an RPM of your module distribution is to run the\n`bdist_rpm` command:\n```text\n\npython setup.py bdist_rpm\n```\nor the `bdist` command with the --format option:\n```text\n\npython setup.py bdist --formats=rpm\n```\nThe former allows you to specify RPM-specific options; the latter allows\nyou to easily specify multiple formats in one run. If you need to do\nboth, you can explicitly specify multiple `bdist_*` commands\nand their options:\n```text\n\npython setup.py bdist_rpm --packager=\"John Doe <jdoe@python.net>\" \\\nbdist_wininst --target_version=\"2.0\"\n```\nCreating RPM packages is driven by a .spec file, much as using\nthe Distutils is driven by the setup script. To make your life easier,\nthe `bdist_rpm` command normally creates a .spec file\nbased on the information you supply in the setup script, on the command\nline, and in any Distutils configuration files. Various options and\nsections in the .spec file are derived from options in the setup\nscript as follows:\nAdditionally, there many options in .spec files that don't have\ncorresponding options in the setup script. Most of these are handled\nthrough options to the `bdist_rpm` command as follows:\nObviously, supplying even a few of these options on the command-line\nwould be tedious and error-prone, so it's usually best to put them in\nthe setup configuration file, setup.cfg--see\nsection 4 (setup-config.html#setup-config). If you distribute or package many Python\nmodule distributions, you might want to put options that apply to all of\nthem in your personal Distutils configuration file\n( /.pydistutils.cfg).\nThere are three steps to building a binary RPM package, all of which are\nhandled automatically by the Distutils:\n1. create a .spec file, which describes the package (analogous\nto the Distutils setup script; in fact, much of the information in the\nsetup script winds up in the .spec file)\n2. create the source RPM\n3. create the ``binary'' RPM (which may or may not contain binary\ncode, depending on whether your module distribution contains Python\nextensions)\nNormally, RPM bundles the last two steps together; when you use the\nDistutils, all three steps are typically bundled together.\nIf you wish, you can separate these three steps. You can use the\n--spec-only option to make `bdist_rpm` just\ncreate the .spec file and exit; in this case, the .spec\nfile will be written to the ``distribution directory''--normally\ndist/, but customizable with the --dist-dir\noption. (Normally, the .spec file winds up deep in the ``build\ntree,'' in a temporary directory created by `bdist_rpm`.)\n** this isn't implemented yet--is it needed?! **\nYou can also specify a custom .spec file with the\n--spec-file option; used in conjunction with\n--spec-only, this gives you an opportunity to customize\nthe .spec file manually:\n```text\n\n> python setup.py bdist_rpm --spec-only\n# ...edit dist/FooBar-1.0.spec\n> python setup.py bdist_rpm --spec-file=dist/FooBar-1.0.spec\n```\n(Although a better way to do this is probably to override the standard\n`bdist_rpm` command with one that writes whatever else you want\nto the .spec file; see section #extending for information on\nextending the Distutils.)\n## 6.3 Creating Windows installers\nExecutable Windows installers are the natural format for binary\ndistributions on Windows. They display a nice GUI interface, display\nsome information of the module distribution to be installed, taken\nfrom the meta-dada in the setup script, let the user select a few\n(currently maybe too few) options, and start or cancel the installation.\nSince the meta-data is taken from the setup script, creating\nWindows installers is usually as easy as running:\n```text\n\npython setup.py bdist_wininst\n```\nor the `bdist` command with the --format option:\n```text\n\npython setup.py bdist --formats=wininst\n```\nIf you have a pure module distribution (only containing pure\nPython modules and packages), the resulting installer will be\nversion independent and have a name like Foo-1.0.win32.exe.\nThese installers can even be created on Unix or MacOS platforms.\nIf you have a non-pure distribution, the extensions can only be\ncreated on a Windows platform, and will be Python version dependend.\nThe installer filename will reflect this and now has the form\nFoo-1.0.win32-py2.0.exe. You have to create a separate installer\nfor every Python version you want to support.\nThe installer will try to compile pure modules into bytecode after\ninstallation on the target system in normal and optimizing mode.\nIf you don't want this to happen for some reason, you can run\nthe bdist_wininst command with the --no-target-compile and/or\nthe --no-target-optimize option.", "python_version": "2.1", "length": 9993, "url": "https://docs.python.org/2.0/dist/creating-wininst.html"}
{"title": "Distributing Python Modules", "text": "../index.html | intro.html | Distributing Python Modules\n---\n# Distributing Python Modules\nGreg Ward\nE-mail: gward@python.net\n### Abstract:\nThis document describes the Python Distribution Utilities\n(``Distutils'') from the module developer's point-of-view, describing\nhow to use the Distutils to make Python modules and extensions easily\navailable to a wider audience with very little overhead for\nbuild/release/install mechanics.", "python_version": "2.1", "length": 430, "url": "https://docs.python.org/2.0/dist/dist.html"}
{"title": "Distributing Python Modules", "text": "../index.html | intro.html | Distributing Python Modules\n---\n# Distributing Python Modules\nGreg Ward\nE-mail: gward@python.net\n### Abstract:\nThis document describes the Python Distribution Utilities\n(``Distutils'') from the module developer's point-of-view, describing\nhow to use the Distutils to make Python modules and extensions easily\navailable to a wider audience with very little overhead for\nbuild/release/install mechanics.", "python_version": "2.1", "length": 430, "url": "https://docs.python.org/2.0/dist/index.html"}
{"title": "1 Introduction", "text": "dist.html | dist.html | simple-example.html | Distributing Python Modules\n---\n# 1 Introduction\nIn the past, Python module developers have not had much infrastructure\nsupport for distributing modules, nor have Python users had much support\nfor installing and maintaining third-party modules. With the\nintroduction of the Python Distribution Utilities (Distutils for short)\nin Python 1.6, this situation should start to improve.\nThis document only covers using the Distutils to distribute your Python\nmodules. Using the Distutils does not tie you to Python 1.6, though:\nthe Distutils work just fine with Python 1.5.2, and it is reasonable\n(and expected to become commonplace) to expect users of Python 1.5.2 to\ndownload and install the Distutils separately before they can install\nyour modules. Python 1.6 (or later) users, of course, won't have to add\nanything to their Python installation in order to use the Distutils to\ninstall third-party modules.\nThis document concentrates on the role of developer/distributor: if\nyou're looking for information on installing Python modules, you\nshould refer to the Installing Python\nModules (../inst/inst.html) manual.", "python_version": "2.1", "length": 1157, "url": "https://docs.python.org/2.0/dist/intro.html"}
{"title": "7 Reference", "text": "creating-wininst.html | dist.html | bdist-cmds.html | Distributing Python Modules\n---\n- 7.1 Installing modules: the `install` command family (sdist-cmd.html#SECTION000710000000000000000)\n - 7.1.1 `install_data` (sdist-cmd.html#SECTION000711000000000000000)\n 7.1.2 `install_scripts` (sdist-cmd.html#SECTION000712000000000000000)\n 7.2 Creating a source distribution: the\n `sdist` command (sdist-cmd.html#SECTION000720000000000000000)\n---\n# 7 Reference\n## 7.1 Installing modules: the `install` command family\nThe install command ensures that the build commands have been run and then\nruns the subcommands `install_lib`,\n`install_data` and\n`install_scripts`.\n### 7.1.1 `install_data`\nThis command installs all data files provided with the distribution.\n### 7.1.2 `install_scripts`\nThis command installs all (Python) scripts in the distribution.\n## 7.2 Creating a source distribution: the\n`sdist` command\n** fragment moved down from above: needs context! **\nThe manifest template commands are:\nThe patterns here are Unix-style ``glob'' patterns: `*` matches any\nsequence of regular filename characters, `?` matches any single\nregular filename character, and `[ range ]` matches any of the\ncharacters in range (e.g., `a-z`, `a-zA-Z`,\n`a-f0-9_.`). The definition of ``regular filename character'' is\nplatform-specific: on Unix it is anything except slash; on Windows\nanything except backslash or colon; on MacOS anything except colon.\n** Windows and MacOS support not there yet **", "python_version": "2.1", "length": 1477, "url": "https://docs.python.org/2.0/dist/sdist-cmd.html"}
{"title": "4 Writing the Setup Configuration File", "text": "setup-script.html | dist.html | source-dist.html | Distributing Python Modules\n---\n# 4 Writing the Setup Configuration File\nOften, it's not possible to write down everything needed to build a\ndistribution a priori: you may need to get some information from\nthe user, or from the user's system, in order to proceed. As long as\nthat information is fairly simple--a list of directories to search for\nC header files or libraries, for example--then providing a\nconfiguration file, setup.cfg, for users to edit is a cheap and\neasy way to solicit it. Configuration files also let you provide\ndefault values for any command option, which the installer can then\noverride either on the command-line or by editing the config file.\n(If you have more advanced needs, such as determining which extensions\nto build based on what capabilities are present on the target system,\nthen you need the Distutils ``auto-configuration'' facility. This\nstarted to appear in Distutils 0.9 but, as of this writing, isn't mature\nor stable enough yet for real-world use.)\nThe setup configuration file is a useful middle-ground between the setup\nscript--which, ideally, would be opaque to installers2 (#foot247)--and the command-line to the setup\nscript, which is outside of your control and entirely up to the\ninstaller. In fact, setup.cfg (and any other Distutils\nconfiguration files present on the target system) are processed after\nthe contents of the setup script, but before the command-line. This has\nseveral useful consequences:\n- installers can override some of what you put in setup.py by\nediting setup.cfg\n- you can provide non-standard defaults for options that are not\neasily set in setup.py\n- installers can override anything in setup.cfg using the\ncommand-line options to setup.py\nThe basic syntax of the configuration file is simple:\n```text\n\n[command]\noption=value\n...\n```\nwhere command is one of the Distutils commands (e.g.\n`build_py`, `install`), and option is one of the\noptions that command supports. Any number of options can be supplied\nfor each command, and any number of command sections can be included in\nthe file. Blank lines are ignored, as are comments (from a\n\"#\" character to end-of-line). Long option values can be\nsplit across multiple lines simply by indenting the continuation lines.\nYou can find out the list of options supported by a particular command\nwith the universal --help option, e.g.\n```text\n\n> python setup.py --help build_ext\n[...]\nOptions for 'build_ext' command:\n--build-lib (-b) directory for compiled extension modules\n--build-temp (-t) directory for temporary files (build by-products)\n--inplace (-i) ignore build-lib and put compiled extensions into the\nsource directory alongside your pure Python modules\n--include-dirs (-I) list of directories to search for header files\n--define (-D) C preprocessor macros to define\n--undef (-U) C preprocessor macros to undefine\n[...]\n```\nOr consult section 7 (sdist-cmd.html#reference) of this document (the command\nreference).\nNote that an option spelled --foo-bar on the command-line\nis spelled foo_bar in configuration files.\nFor example, say you want your extensions to be built\n``in-place''--that is, you have an extension pkg.ext, and you\nwant the compiled extension file (ext.so on Unix, say) to be put\nin the same source directory as your pure Python modules\npkg.mod1 and pkg.mod2. You can always use the\n--inplace option on the command-line to ensure this:\n```text\n\npython setup.py build_ext --inplace\n```\nBut this requires that you always specify the `build_ext`\ncommand explicitly, and remember to provide --inplace.\nAn easier way is to ``set and forget'' this option, by encoding it in\nsetup.cfg, the configuration file for this distribution:\n```text\n\n[build_ext]\ninplace=1\n```\nThis will affect all builds of this module distribution, whether or not\nyou explcitly specify `build_ext`. If you include\nsetup.cfg in your source distribution, it will also affect\nend-user builds--which is probably a bad idea for this option, since\nalways building extensions in-place would break installation of the\nmodule distribution. In certain peculiar cases, though, modules are\nbuilt right in their installation directory, so this is conceivably a\nuseful ability. (Distributing extensions that expect to be built in\ntheir installation directory is almost always a bad idea, though.)\nAnother example: certain commands take a lot of options that don't\nchange from run-to-run; for example, `bdist_rpm` needs to know\neverything required to generate a ``spec'' file for creating an RPM\ndistribution. Some of this information comes from the setup script, and\nsome is automatically generated by the Distutils (such as the list of\nfiles installed). But some of it has to be supplied as options to\n`bdist_rpm`, which would be very tedious to do on the\ncommand-line for every run. Hence, here is a snippet from the\nDistutils' own setup.cfg:\n```text\n\n[bdist_rpm]\nrelease = 1\npackager = Greg Ward <gward@python.net>\ndoc_files = CHANGES.txt\nREADME.txt\nUSAGE.txt\ndoc/\nexamples/\n```\nNote that the doc_files option is simply a\nwhitespace-separated string split across multiple lines for readability.\nSee Also:", "python_version": "2.1", "length": 5153, "url": "https://docs.python.org/2.0/dist/setup-config.html"}
{"title": "3 Writing the Setup Script", "text": "simple-example.html | dist.html | setup-config.html | Distributing Python Modules\n---\n- 3.1 Listing whole packages (setup-script.html#SECTION000310000000000000000)\n 3.2 Listing individual modules (setup-script.html#SECTION000320000000000000000)\n 3.3 Describing extension modules (setup-script.html#SECTION000330000000000000000)\n - 3.3.1 Extension names and packages (setup-script.html#SECTION000331000000000000000)\n 3.3.2 Extension source files (setup-script.html#SECTION000332000000000000000)\n 3.3.3 Preprocessor options (setup-script.html#SECTION000333000000000000000)\n 3.3.4 Library options (setup-script.html#SECTION000334000000000000000)\n 3.3.5 Other options (setup-script.html#SECTION000335000000000000000)\n 3.4 Listing scripts (setup-script.html#SECTION000340000000000000000)\n 3.5 Listing additional files (setup-script.html#SECTION000350000000000000000)\n---\n# 3 Writing the Setup Script\nThe setup script is the centre of all activity in building,\ndistributing, and installing modules using the Distutils. The main\npurpose of the setup script is to describe your module distribution to\nthe Distutils, so that the various commands that operate on your modules\ndo the right thing. As we saw in section 2.1 (simple-example.html#simple-example) above,\nthe setup script consists mainly of a call to setup(), and\nmost information supplied to the Distutils by the module developer is\nsupplied as keyword arguments to setup().\nHere's a slightly more involved example, which we'll follow for the next\ncouple of sections: the Distutils' own setup script. (Keep in mind that\nalthough the Distutils are included with Python 1.6 and later, they also\nhave an independent existence so that Python 1.5.2 users can use them to\ninstall other module distributions. The Distutils' own setup script,\nshown here, is used to install the package into Python 1.5.2.)\n```text\n\n#!/usr/bin/env python\n\nfrom distutils.core import setup\n\nsetup(name=\"Distutils\",\nversion=\"1.0\",\ndescription=\"Python Distribution Utilities\",\nauthor=\"Greg Ward\",\nauthor_email=\"gward@python.net\",\nurl=\"http://www.python.org/sigs/distutils-sig/\",\npackages=['distutils', 'distutils.command'],\n)\n```\nThere are only two differences between this and the trivial one-file\ndistribution presented in section 2.1 (simple-example.html#simple-example): more\nmeta-data, and the specification of pure Python modules by package,\nrather than by module. This is important since the Distutils consist of\na couple of dozen modules split into (so far) two packages; an explicit\nlist of every module would be tedious to generate and difficult to\nmaintain.\nNote that any pathnames (files or directories) supplied in the setup\nscript should be written using the Unix convention, i.e.\nslash-separated. The Distutils will take care of converting this\nplatform-neutral representation into whatever is appropriate on your\ncurrent platform before actually using the pathname. This makes your\nsetup script portable across operating systems, which of course is one\nof the major goals of the Distutils. In this spirit, all pathnames in\nthis document are slash-separated (MacOS programmers should keep in\nmind that the absence of a leading slash indicates a relative\npath, the opposite of the MacOS convention with colons).\nThis, of course, only applies to pathnames given to Distutils functions.\nIf you, for example, use standard python functions such as glob.glob\nor os.listdir to specify files, you should be careful to write portable\ncode instead of hardcoding path separators:\n```text\n\nglob.glob(os.path.join('mydir', 'subdir', '*.html'))\nos.listdir(os.path.join('mydir', 'subdir'))\n```\n## 3.1 Listing whole packages\nThe packages option tells the Distutils to process (build,\ndistribute, install, etc.) all pure Python modules found in each package\nmentioned in the packages list. In order to do this, of\ncourse, there has to be a correspondence between package names and\ndirectories in the filesystem. The default correspondence is the most\nobvious one, i.e. package distutils is found in the directory\ndistutils relative to the distribution root. Thus, when you say\n`packages = ['foo']` in your setup script, you are promising that\nthe Distutils will find a file foo/__init__.py (which might\nbe spelled differently on your system, but you get the idea) relative to\nthe directory where your setup script lives. (If you break this\npromise, the Distutils will issue a warning but process the broken\npackage anyways.)\nIf you use a different convention to lay out your source directory,\nthat's no problem: you just have to supply the package_dir\noption to tell the Distutils about your convention. For example, say\nyou keep all Python source under lib, so that modules in the\n``root package'' (i.e., not in any package at all) are right in\nlib, modules in the foo package are in lib/foo,\nand so forth. Then you would put\n```text\n\npackage_dir = {'': 'lib'}\n```\nin your setup script. (The keys to this dictionary are package names,\nand an empty package name stands for the root package. The values are\ndirectory names relative to your distribution root.) In this case, when\nyou say `packages = ['foo']`, you are promising that the file\nlib/foo/__init__.py exists.\nAnother possible convention is to put the foo package right in\nlib, the foo.bar package in lib/bar, etc. This\nwould be written in the setup script as\n```text\n\npackage_dir = {'foo': 'lib'}\n```\nA `package : dir` entry in the package_dir\ndictionary implicitly applies to all packages below package, so\nthe foo.bar case is automatically handled here. In this\nexample, having `packages = ['foo', 'foo.bar']` tells the Distutils\nto look for lib/__init__.py and\nlib/bar/__init__.py. (Keep in mind that although\npackage_dir applies recursively, you must explicitly list all\npackages in packages: the Distutils will not recursively\nscan your source tree looking for any directory with an\n__init__.py file.)\n## 3.2 Listing individual modules\nFor a small module distribution, you might prefer to list all modules\nrather than listing packages--especially the case of a single module\nthat goes in the ``root package'' (i.e., no package at all). This\nsimplest case was shown in section 2.1 (simple-example.html#simple-example); here is a\nslightly more involved example:\n```text\n\npy_modules = ['mod1', 'pkg.mod2']\n```\nThis describes two modules, one of them in the ``root'' package, the\nother in the pkg package. Again, the default package/directory\nlayout implies that these two modules can be found in mod1.py and\npkg/mod2.py, and that pkg/__init__.py exists as well.\nAnd again, you can override the package/directory correspondence using\nthe package_dir option.\n## 3.3 Describing extension modules\nJust as writing Python extension modules is a bit more complicated than\nwriting pure Python modules, describing them to the Distutils is a bit\nmore complicated. Unlike pure modules, it's not enough just to list\nmodules or packages and expect the Distutils to go out and find the\nright files; you have to specify the extension name, source file(s), and\nany compile/link requirements (include directories, libraries to link\nwith, etc.).\nAll of this is done through another keyword argument to\nsetup(), the extensions option. extensions\nis just a list of Extension instances, each of which describes a\nsingle extension module. Suppose your distribution includes a single\nextension, called foo and implemented by foo.c. If no\nadditional instructions to the compiler/linker are needed, describing\nthis extension is quite simple:\n```text\n\nExtension(\"foo\", [\"foo.c\"])\n```\nThe Extension class can be imported from\ndistutils.core, along with setup(). Thus, the setup\nscript for a module distribution that contains only this one extension\nand nothing else might be:\n```text\n\nfrom distutils.core import setup, Extension\nsetup(name=\"foo\", version=\"1.0\",\next_modules=[Extension(\"foo\", [\"foo.c\"])])\n```\nThe Extension class (actually, the underlying extension-building\nmachinery implemented by the `build_ext` command) supports a\ngreat deal of flexibility in describing Python extensions, which is\nexplained in the following sections.\n### 3.3.1 Extension names and packages\nThe first argument to the Extension constructor is always the\nname of the extension, including any package names. For example,\n```text\n\nExtension(\"foo\", [\"src/foo1.c\", \"src/foo2.c\"])\n```\ndescribes an extension that lives in the root package, while\n```text\n\nExtension(\"pkg.foo\", [\"src/foo1.c\", \"src/foo2.c\"])\n```\ndescribes the same extension in the pkg package. The source\nfiles and resulting object code are identical in both cases; the only\ndifference is where in the filesystem (and therefore where in Python's\nnamespace hierarchy) the resulting extension lives.\nIf you have a number of extensions all in the same package (or all under\nthe same base package), use the ext_package keyword argument\nto setup(). For example,\n```text\n\nsetup(...\next_package=\"pkg\",\next_modules=[Extension(\"foo\", [\"foo.c\"]),\nExtension(\"subpkg.bar\", [\"bar.c\"])]\n)\n```\nwill compile foo.c to the extension pkg.foo, and\nbar.c to pkg.subpkg.bar.\n### 3.3.2 Extension source files\nThe second argument to the Extension constructor is a list of\nsource files. Since the Distutils currently only support C/C++\nextensions, these are normally C/C++ source files. (Be sure to use\nappropriate extensions to distinguish C++ source files: .cc and\n.cpp seem to be recognized by both Unix and Windows compilers.)\nHowever, you can also include SWIG interface (.i) files in the\nlist; the `build_ext` command knows how to deal with SWIG\nextensions: it will run SWIG on the interface file and compile the\nresulting C/C++ file into your extension.\n** SWIG support is rough around the edges and largely untested;\nespecially SWIG support of C++ extensions! Explain in more detail\nhere when the interface firms up. **\nOn some platforms, you can include non-source files that are processed\nby the compiler and included in your extension. Currently, this just\nmeans Windows message text (.mc) files and resource definition\n(.rc) files for Visual C++. These will be compiled to binary resource\n(.res) files and linked into the executable.\n### 3.3.3 Preprocessor options\nThree optional arguments to Extension will help if you need to\nspecify include directories to search or preprocessor macros to\ndefine/undefine: `include_dirs`, `define_macros`, and\n`undef_macros`.\nFor example, if your extension requires header files in the\ninclude directory under your distribution root, use the\n`include_dirs` option:\n```text\n\nExtension(\"foo\", [\"foo.c\"], include_dirs=[\"include\"])\n```\nYou can specify absolute directories there; if you know that your\nextension will only be built on Unix systems with X11R6 installed to\n/usr, you can get away with\n```text\n\nExtension(\"foo\", [\"foo.c\"], include_dirs=[\"/usr/include/X11\"])\n```\nYou should avoid this sort of non-portable usage if you plan to\ndistribute your code: it's probably better to write your code to include\n(e.g.) `<X11/Xlib.h>`.\nIf you need to include header files from some other Python extension,\nyou can take advantage of the fact that the Distutils install extension\nheader files in a consistent way. For example, the Numerical Python\nheader files are installed (on a standard Unix installation) to\n/usr/local/include/python1.5/Numerical. (The exact location will\ndiffer according to your platform and Python installation.) Since the\nPython include directory--/usr/local/include/python1.5 in this\ncase--is always included in the search path when building Python\nextensions, the best approach is to include (e.g.)\n`<Numerical/arrayobject.h>`. If you insist on putting the\nNumerical include directory right into your header search path,\nthough, you can find that directory using the Distutils\nsysconfig module:\n```text\n\nfrom distutils.sysconfig import get_python_inc\nincdir = os.path.join(get_python_inc(plat_specific=1), \"Numerical\")\nsetup(...,\nExtension(..., include_dirs=[incdir]))\n```\nEven though this is quite portable--it will work on any Python\ninstallation, regardless of platform--it's probably easier to just\nwrite your C code in the sensible way.\nYou can define and undefine pre-processor macros with the\n`define_macros` and `undef_macros` options.\n`define_macros` takes a list of `(name, value)` tuples, where\n`name` is the name of the macro to define (a string) and\n`value` is its value: either a string or `None`. (Defining a\nmacro `FOO` to `None` is the equivalent of a bare\n`#define FOO` in your C source: with most compilers, this sets\n`FOO` to the string `1`.) `undef_macros` is just\na list of macros to undefine.\nFor example:\n```text\n\nExtension(...,\ndefine_macros=[('NDEBUG', '1')],\n('HAVE_STRFTIME', None),\nundef_macros=['HAVE_FOO', 'HAVE_BAR'])\n```\nis the equivalent of having this at the top of every C source file:\n```text\n\n#define NDEBUG 1\n#define HAVE_STRFTIME\n#undef HAVE_FOO\n#undef HAVE_BAR\n```\n### 3.3.4 Library options\nYou can also specify the libraries to link against when building your\nextension, and the directories to search for those libraries. The\n`libraries` option is a list of libraries to link against,\n`library_dirs` is a list of directories to search for libraries at\nlink-time, and `runtime_library_dirs` is a list of directories to\nsearch for shared (dynamically loaded) libraries at run-time.\nFor example, if you need to link against libraries known to be in the\nstandard library search path on target systems\n```text\n\nExtension(...,\nlibraries=[\"gdbm\", \"readline\"])\n```\nIf you need to link with libraries in a non-standard location, you'll\nhave to include the location in `library_dirs`:\n```text\n\nExtension(...,\nlibrary_dirs=[\"/usr/X11R6/lib\"],\nlibraries=[\"X11\", \"Xt\"])\n```\n(Again, this sort of non-portable construct should be avoided if you\nintend to distribute your code.)\n** Should mention clib libraries here or somewhere else! **\n### 3.3.5 Other options\nThere are still some other options which can be used to handle special\ncases.\nThe extra_objects option is a list of object files to be passed\nto the linker. These files must not have extensions, as the default\nextension for the compiler is used.\nextra_compile_args and extra_link_args can be used\nto specify additional command line options for the compiler resp.\nthe linker command line.\nexport_symbols is only useful on windows, it can contain a list\nof symbols (functions or variables) to be exported. This option\nis not needed when building compiled extensions: the `initmodule`\nfunction will automatically be added to the exported symbols list\nby Distutils.\n## 3.4 Listing scripts\nSo far we have been dealing with pure and non-pure Python modules,\nwhich are usually not run by themselves but imported by scripts.\nScripts are files containing Python source code, indended to be started\nfrom the command line.\nDistutils doesn't provide much functionality for the scripts: the only\nsupport Distutils gives is to adjust the first line of the script\nif it starts with `#!` and contains the word ``python'' to refer\nto the current interpreter location.\nThe scripts option simply is a list of files to be handled\nin this way.\n## 3.5 Listing additional files\nThe data_files option can be used to specify additional\nfiles needed by the module distribution: configuration files,\ndata files, anything which does not fit in the previous categories.\ndata_files specify a sequence of `(directory, files)`\npairs in the following way:\n```text\n\nsetup(...\ndata_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),\n('config', ['cfg/data.cfg'])])\n```\nNote that you can specify the directory names where the data files\nwill be installed, but you cannot rename the data files themselves.\nYou can specify the data_files options as a simple sequence\nof files without specifying a target directory, but this is not recommended,\nand the `install` command will print a warning in this case.\nTo install data files directly in the target directory, an empty\nstring should be given as the directory.", "python_version": "2.1", "length": 15909, "url": "https://docs.python.org/2.0/dist/setup-script.html"}
{"title": "2 Concepts & Terminology", "text": "intro.html | dist.html | setup-script.html | Distributing Python Modules\n---\n- 2.1 A simple example (simple-example.html#SECTION000210000000000000000)\n 2.2 General Python terminology (simple-example.html#SECTION000220000000000000000)\n 2.3 Distutils-specific terminology (simple-example.html#SECTION000230000000000000000)\n---\n# 2 Concepts & Terminology\nUsing the Distutils is quite simple, both for module developers and for\nusers/administrators installing third-party modules. As a developer,\nyour responsibilities (apart from writing solid, well-documented and\nwell-tested code, of course!) are:\n- write a setup script (setup.py by convention)\n- (optional) write a setup configuration file\n- create a source distribution\n- (optional) create one or more built (binary) distributions\nEach of these tasks is covered in this document.\nNot all module developers have access to a multitude of platforms, so\nit's not always feasible to expect them to create a multitude of built\ndistributions. It is hoped that a class of intermediaries, called\npackagers, will arise to address this need. Packagers will take\nsource distributions released by module developers, build them on one or\nmore platforms, and release the resulting built distributions. Thus,\nusers on the most popular platforms will be able to install most popular\nPython module distributions in the most natural way for their platform,\nwithout having to run a single setup script or compile a line of code.\n## 2.1 A simple example\nThe setup script is usually quite simple, although since it's written in\nPython, there are no arbitrary limits to what you can do with\nit.1 (#foot685) If\nall you want to do is distribute a module called foo, contained\nin a file foo.py, then your setup script can be as little as\nthis:\n```text\n\nfrom distutils.core import setup\nsetup(name=\"foo\",\nversion=\"1.0\",\npy_modules=[\"foo\"])\n```\nSome observations:\n- most information that you supply to the Distutils is supplied as\nkeyword arguments to the setup() function\n- those keyword arguments fall into two categories: package\nmeta-data (name, version number) and information about what's in the\npackage (a list of pure Python modules, in this case)\n- modules are specified by module name, not filename (the same will\nhold true for packages and extensions)\n- it's recommended that you supply a little more meta-data, in\nparticular your name, email address and a URL for the project\n(see section 3 (setup-script.html#setup-script) for an example)\nTo create a source distribution for this module, you would create a\nsetup script, setup.py, containing the above code, and run:\n```text\n\npython setup.py sdist\n```\nwhich will create an archive file (e.g., tarball on Unix, ZIP file on\nWindows) containing your setup script, setup.py, and your module,\nfoo.py. The archive file will be named Foo-1.0.tar.gz (or\n.zip), and will unpack into a directory Foo-1.0.\nIf an end-user wishes to install your foo module, all she has\nto do is download Foo-1.0.tar.gz (or .zip), unpack it,\nand--from the Foo-1.0 directory--run\n```text\n\npython setup.py install\n```\nwhich will ultimately copy foo.py to the appropriate directory\nfor third-party modules in their Python installation.\nThis simple example demonstrates some fundamental concepts of the\nDistutils: first, both developers and installers have the same basic\nuser interface, i.e. the setup script. The difference is which\nDistutils commands they use: the `sdist` command is\nalmost exclusively for module developers, while `install` is\nmore often for installers (although most developers will want to install\ntheir own code occasionally).\nIf you want to make things really easy for your users, you can create\none or more built distributions for them. For instance, if you are\nrunning on a Windows machine, and want to make things easy for other\nWindows users, you can create an executable installer (the most\nappropriate type of built distribution for this platform) with the\n`bdist_wininst` command. For example:\n```text\n\npython setup.py bdist_wininst\n```\nwill create an executable installer, Foo-1.0.win32.exe, in the\ncurrent directory.\nCurrently (Distutils 0.9.2), the only other useful built\ndistribution format is RPM, implemented by the `bdist_rpm`\ncommand. For example, the following command will create an RPM file\ncalled Foo-1.0.noarch.rpm:\n```text\n\npython setup.py bdist_rpm\n```\n(This uses the `rpm` command, so has to be run on an RPM-based\nsystem such as Red Hat Linux, SuSE Linux, or Mandrake Linux.)\nYou can find out what distribution formats are available at any time by\nrunning\n```text\n\npython setup.py bdist --help-formats\n```\n## 2.2 General Python terminology\nIf you're reading this document, you probably have a good idea of what\nmodules, extensions, and so forth are. Nevertheless, just to be sure\nthat everyone is operating from a common starting point, we offer the\nfollowing glossary of common Python terms:\nmodule: the basic unit of code reusability in Python: a block of\ncode imported by some other code. Three types of modules concern us\nhere: pure Python modules, extension modules, and packages.\npure Python module: a module written in Python and contained in a\nsingle .py file (and possibly associated .pyc and/or\n.pyo files). Sometimes referred to as a ``pure module.''\nextension module: a module written in the low-level language of\nthe Python implementation: C/C++ for Python, Java for JPython.\nTypically contained in a single dynamically loadable pre-compiled\nfile, e.g. a shared object (.so) file for Python extensions on\nUnix, a DLL (given the .pyd extension) for Python extensions\non Windows, or a Java class file for JPython extensions. (Note that\ncurrently, the Distutils only handles C/C++ extensions for Python.)\npackage: a module that contains other modules; typically contained\nin a directory in the filesystem and distinguished from other\ndirectories by the presence of a file __init__.py.\nroot package: the root of the hierarchy of packages. (This isn't\nreally a package, since it doesn't have an __init__.py\nfile. But we have to call it something.) The vast majority of the\nstandard library is in the root package, as are many small, standalone\nthird-party modules that don't belong to a larger module collection.\nUnlike regular packages, modules in the root package can be found in\nmany directories: in fact, every directory listed in `sys.path`\ncan contribute modules to the root package.\n## 2.3 Distutils-specific terminology\nThe following terms apply more specifically to the domain of\ndistributing Python modules using the Distutils:\nmodule distribution: a collection of Python modules distributed\ntogether as a single downloadable resource and meant to be installed\nen masse. Examples of some well-known module distributions are\nNumeric Python, PyXML, PIL (the Python Imaging Library), or\nmxDateTime. (This would be called a package, except that term\nis already taken in the Python context: a single module distribution\nmay contain zero, one, or many Python packages.)\npure module distribution: a module distribution that contains only\npure Python modules and packages. Sometimes referred to as a ``pure\ndistribution.''\nnon-pure module distribution: a module distribution that contains\nat least one extension module. Sometimes referred to as a ``non-pure\ndistribution.''\ndistribution root: the top-level directory of your source tree (or\nsource distribution); the directory where setup.py exists and\nis run from", "python_version": "2.1", "length": 7429, "url": "https://docs.python.org/2.0/dist/simple-example.html"}
{"title": "5 Creating a Source Distribution", "text": "setup-config.html | dist.html | creating-wininst.html | Distributing Python Modules\n---\n- 5.1 Specifying the files to distribute (source-dist.html#SECTION000510000000000000000)\n 5.2 Manifest-related options (source-dist.html#SECTION000520000000000000000)\n---\n# 5 Creating a Source Distribution\nAs shown in section 2.1 (simple-example.html#simple-example), you use the\n`sdist` command to create a source distribution. In the\nsimplest case,\n```text\n\npython setup.py sdist\n```\n(assuming you haven't specified any `sdist` options in the setup\nscript or config file), `sdist` creates the archive of the\ndefault format for the current platform. The default format is gzip'ed\ntar file (.tar.gz) on Unix, and ZIP file on Windows.\n** no MacOS support here **\nYou can specify as many formats as you like using the\n--formats option, for example:\n```text\n\npython setup.py sdist --formats=gztar,zip\n```\nto create a gzipped tarball and a zip file. The available formats are:\nNotes:\n(1): default on Windows\n(2): default on Unix\n(3): requires either external zip utility or\nzipfile module (not part of the standard Python library)\n(4): requires external utilities: tar and possibly one\nof gzip, bzip2, or compress\n## 5.1 Specifying the files to distribute\nIf you don't supply an explicit list of files (or instructions on how to\ngenerate one), the `sdist` command puts a minimal default set\ninto the source distribution:\n- all Python source files implied by the py_modules and\npackages options\n- all C source files mentioned in the ext_modules or\nlibraries options (** getting C library sources currently\nbroken - no get_source_files() method in build_clib.py! **)\n- anything that looks like a test script: test/test*.py\n(currently, the Distutils don't do anything with test scripts except\ninclude them in source distributions, but in the future there will be\na standard for testing Python module distributions)\n- README.txt (or README), setup.py (or whatever\nyou called your setup script), and setup.cfg\nSometimes this is enough, but usually you will want to specify\nadditional files to distribute. The typical way to do this is to write\na manifest template, called MANIFEST.in by default. The\nmanifest template is just a list of instructions for how to generate\nyour manifest file, MANIFEST, which is the exact list of files to\ninclude in your source distribution. The `sdist` command\nprocesses this template and generates a manifest based on its\ninstructions and what it finds in the filesystem.\nIf you prefer to roll your own manifest file, the format is simple: one\nfilename per line, regular files (or symlinks to them) only. If you do\nsupply your own MANIFEST, you must specify everything: the\ndefault set of files described above does not apply in this case.\nThe manifest template has one command per line, where each command\nspecifies a set of files to include or exclude from the source\ndistribution. For an example, again we turn to the Distutils' own\nmanifest template:\n```text\n\ninclude *.txt\nrecursive-include examples *.txt *.py\nprune examples/sample?/build\n```\nThe meanings should be fairly clear: include all files in the\ndistribution root matching `*.txt`, all files anywhere under the\nexamples directory matching `*.txt` or `*.py`, and\nexclude all directories matching `examples/sample?/build`. All of\nthis is done after the standard include set, so you can exclude\nfiles from the standard set with explicit instructions in the manifest\ntemplate. (Or, you can use the --no-defaults option to\ndisable the standard set entirely.) There are several other commands\navailable in the manifest template mini-language; see\nsection 7.2 (sdist-cmd.html#sdist-cmd).\nThe order of commands in the manifest template matters: initially, we\nhave the list of default files as described above, and each command in\nthe template adds to or removes from that list of files. Once we have\nfully processed the manifest template, we remove files that should not\nbe included in the source distribution:\n- all files in the Distutils ``build'' tree (default build/)\n- all files in directories named RCS or CVS\nNow we have our complete list of files, which is written to the manifest\nfor future reference, and then used to build the source distribution\narchive(s).\nYou can disable the default set of included files with the\n--no-defaults option, and you can disable the standard\nexclude set with --no-prune.\nFollowing the Distutils' own manifest template, let's trace how the\n`sdist` command builds the list of files to include in the\nDistutils source distribution:\n1. include all Python source files in the distutils and\ndistutils/command subdirectories (because packages\ncorresponding to those two directories were mentioned in the\npackages option in the setup script--see\nsection 3 (setup-script.html#setup-script))\n2. include README.txt, setup.py, and setup.cfg\n(standard files)\n3. include test/test*.py (standard files)\n4. include *.txt in the distribution root (this will find\nREADME.txt a second time, but such redundancies are weeded out\nlater)\n5. include anything matching *.txt or *.py in the\nsub-tree under examples,\n6. exclude all files in the sub-trees starting at directories\nmatching examples/sample?/build--this may exclude files\nincluded by the previous two steps, so it's important that the\n`prune` command in the manifest template comes after the\n`recursive-include` command\n7. exclude the entire build tree, and any RCS or\nCVS directories\nJust like in the setup script, file and directory names in the manifest\ntemplate should always be slash-separated; the Distutils will take care\nof converting them to the standard representation on your platform.\nThat way, the manifest template is portable across operating systems.\n## 5.2 Manifest-related options\nThe normal course of operations for the `sdist` command is as\nfollows:\n- if the manifest file, MANIFEST doesn't exist, read\nMANIFEST.in and create the manifest\n- if neither MANIFEST nor MANIFEST.in exist, create a\nmanifest with just the default file set3 (#foot692)\n- if either MANIFEST.in or the setup script (setup.py)\nare more recent than MANIFEST, recreate MANIFEST by\nreading MANIFEST.in\n- use the list of files now in MANIFEST (either just\ngenerated or read in) to create the source distribution archive(s)\nThere are a couple of options that modify this behaviour. First, use\nthe --no-defaults and --no-prune to\ndisable the standard ``include'' and ``exclude'' sets.4 (#foot693)\nSecond, you might want to force the manifest to be regenerated--for\nexample, if you have added or removed files or directories that match an\nexisting pattern in the manifest template, you should regenerate the\nmanifest:\n```text\n\npython setup.py sdist --force-manifest\n```\nOr, you might just want to (re)generate the manifest, but not create a\nsource distribution:\n```text\n\npython setup.py sdist --manifest-only\n```\n--manifest-only implies --force-manifest.\n-o is a shortcut for --manifest-only, and\n-f for --force-manifest.", "python_version": "2.1", "length": 6955, "url": "https://docs.python.org/2.0/dist/source-dist.html"}
{"title": "About this document ...", "text": "discussion.html | doc.html | Documenting Python | contents.html\n---\n# About this document ...\nDocumenting Python,\nApril 15, 2001, Release 2.1\nThis document was generated using the LaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) translator.\nLaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) is Copyright ©\n1993, 1994, 1995, 1996, 1997, Nikos\nDrakos (http://cbl.leeds.ac.uk/nikos/personal.html), Computer Based Learning Unit, University of\nLeeds, and Copyright © 1997, 1998, Ross\nMoore (http://www.maths.mq.edu.au/~ross/), Mathematics Department, Macquarie University,\nSydney.\nThe application of LaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) to the Python\ndocumentation has been heavily tailored by Fred L. Drake,\nJr. Original navigation icons were contributed by Christopher\nPetrilli.\n---\n## Comments and Questions\nGeneral comments and questions regarding this document should\nbe sent by email to python-docs@python.org (mailto:python-docs@python.org). If you find specific errors in\nthis document, please report the bug at the Python Bug\nTracker (http://sourceforge.net/bugs/?group_id=5470) at SourceForge (http://sourceforge.net/).\nQuestions regarding how to use the information in this\ndocument should be sent to the Python news group, comp.lang.python (news:comp.lang.python), or the Python mailing list (http://www.python.org/mailman/listinfo/python-list) (which is gated to the newsgroup and\ncarries the same content).\nFor any of these channels, please be sure not to send HTML email.\nThanks.\n---\ndiscussion.html | doc.html | Documenting Python | contents.html\n---\nRelease 2.1, documentation updated on April 15, 2001.", "python_version": "2.1", "length": 1656, "url": "https://docs.python.org/2.0/doc/about.html"}
{"title": "4 Document Classes", "text": "node6.html | doc.html | node8.html | Documenting Python | contents.html\n---\n# 4 Document Classes\nTwo LATEX document classes are defined specifically for use with\nthe Python documentation. The `manual` class is for large\ndocuments which are sectioned into chapters, and the `howto`\nclass is for smaller documents.\nThe `manual` documents are larger and are used for most of the\nstandard documents. This document class is based on the standard\nLATEX `report` class and is formatted very much like a long\ntechnical report. The Python Reference\nManual (../ref/ref.html) is a good example of a `manual` document, and the\nPython Library Reference (../lib/lib.html) is a large\nexample.\nThe `howto` documents are shorter, and don't have the large\nstructure of the `manual` documents. This class is based on\nthe standard LATEX `article` class and is formatted somewhat\nlike the Linux Documentation Project's ``HOWTO'' series as done\noriginally using the LinuxDoc software. The original intent for the\ndocument class was that it serve a similar role as the LDP's HOWTO\nseries, but the applicability of the class turns out to be somewhat\nbroader. This class is used for ``how-to'' documents (this\ndocument is an example) and for shorter reference manuals for small,\nfairly cohesive module libraries. Examples of the later use include\nthe standard Macintosh Library Modules (../mac/mac.html)\nand\nUsing\nKerberos from Python (http://starship.python.net/crew/fdrake/manuals/krb5py/krb5py.html), which contains reference material for an\nextension package. These documents are roughly equivalent to a\nsingle chapter from a larger work.", "python_version": "2.1", "length": 1617, "url": "https://docs.python.org/2.0/doc/classes.html"}
{"title": "Contents", "text": "doc.html | doc.html | node2.html | Documenting Python\n---\n## Contents\nTable of Contents\n- Contents (contents.html)\n 1 Introduction (node2.html)\n 2 Directory Structure (node3.html)\n 3 LATEX Primer (latex-primer.html)\n - 3.1 Syntax (node5.html)\n 3.2 Hierarchical Structure (node6.html)\n 4 Document Classes (classes.html)\n 5 Special Markup Constructs (node8.html)\n - 5.1 Markup for the Preamble (preamble-info.html)\n 5.2 Meta-information Markup (meta-info.html)\n 5.3 Information Units (info-units.html)\n 5.4 Showing Code Examples (node12.html)\n 5.5 Inline Markup (node13.html)\n 5.6 Module-specific Markup (node14.html)\n 5.7 Library-level Markup (node15.html)\n 5.8 Table Markup (node16.html)\n 5.9 Reference List Markup (references.html)\n 5.10 Index-generating Markup (indexing.html)\n 6 Special Names (node19.html)\n 7 Processing Tools (node20.html)\n - 7.1 External Tools (node21.html)\n 7.2 Internal Tools (node22.html)\n 8 Future Directions (futures.html)\n - 8.1 Structured Documentation (structured.html)\n 8.2 Discussion Forums (discussion.html)\n About this document ... (about.html)\nEnd of Table of Contents", "python_version": "2.1", "length": 1128, "url": "https://docs.python.org/2.0/doc/contents.html"}
{"title": "8.2 Discussion Forums", "text": "structured.html | futures.html | about.html | Documenting Python | contents.html\n---\n## 8.2 Discussion Forums\nDiscussion of the future of the Python documentation and related\ntopics takes place in the Documentation Special Interest Group, or\n``Doc-SIG.'' Information on the group, including mailing list\narchives and subscription information, is available at\nhttp://www.python.org/sigs/doc-sig/. The SIG is open to all\ninterested parties.\nComments and bug reports on the standard documents should be sent\nto python-docs@python.org. This may include comments\nabout formatting, content, grammatical and spelling errors, or\nthis document. You can also send comments on this document\ndirectly to the author at fdrake@acm.org.", "python_version": "2.1", "length": 721, "url": "https://docs.python.org/2.0/doc/discussion.html"}
{"title": "Documenting Python", "text": "../index.html | contents.html | Documenting Python | contents.html\n---\n# Documenting Python\nFred L. Drake, Jr.\nPythonLabs\nE-mail: fdrake@acm.org\nRelease 2.1\nApril 15, 2001\n### Abstract:\nThe Python language has a substantial body of\ndocumentation, much of it contributed by various authors. The markup\nused for the Python documentation is based on LATEX and requires a\nsignificant set of macros written specifically for documenting Python.\nThis document describes the macros introduced to support Python\ndocumentation and how they should be used to support a wide range of\noutput formats.\nThis document describes the document classes and special markup used\nin the Python documentation. Authors may use this guide, in\nconjunction with the template files provided with the\ndistribution, to create or maintain whole documents or sections.", "python_version": "2.1", "length": 835, "url": "https://docs.python.org/2.0/doc/doc.html"}
{"title": "8 Future Directions", "text": "node22.html | doc.html | structured.html | Documenting Python | contents.html\n---\n# 8 Future Directions\nThe history of the Python documentation is full of changes, most of\nwhich have been fairly small and evolutionary. There has been a\ngreat deal of discussion about making large changes in the markup\nlanguages and tools used to process the documentation. This section\ndeals with the nature of the changes and what appears to be the most\nlikely path of future development.", "python_version": "2.1", "length": 473, "url": "https://docs.python.org/2.0/doc/futures.html"}
{"title": "Documenting Python", "text": "../index.html | contents.html | Documenting Python | contents.html\n---\n# Documenting Python\nFred L. Drake, Jr.\nPythonLabs\nE-mail: fdrake@acm.org\nRelease 2.1\nApril 15, 2001\n### Abstract:\nThe Python language has a substantial body of\ndocumentation, much of it contributed by various authors. The markup\nused for the Python documentation is based on LATEX and requires a\nsignificant set of macros written specifically for documenting Python.\nThis document describes the macros introduced to support Python\ndocumentation and how they should be used to support a wide range of\noutput formats.\nThis document describes the document classes and special markup used\nin the Python documentation. Authors may use this guide, in\nconjunction with the template files provided with the\ndistribution, to create or maintain whole documents or sections.", "python_version": "2.1", "length": 835, "url": "https://docs.python.org/2.0/doc/index.html"}
{"title": "5.10 Index-generating Markup", "text": "references.html | node8.html | node19.html | Documenting Python | contents.html\n---\n## 5.10 Index-generating Markup\nEffective index generation for technical documents can be very\ndifficult, especially for someone familiar with the topic but not\nthe creation of indexes. Much of the difficulty arises in the\narea of terminology: including the terms an expert would use for a\nconcept is not sufficient. Coming up with the terms that a novice\nwould look up is fairly difficult for an author who, typically, is\nan expert in the area she is writing on.\nThe truly difficult aspects of index generation are not areas with\nwhich the documentation tools can help. However, ease\nof producing the index once content decisions are made is within\nthe scope of the tools. Markup is provided which the processing\nsoftware is able to use to generate a variety of kinds of index\nentry with minimal effort. Additionally, many of the environments\ndescribed in section 5.3 (info-units.html#info-units), ``Information Units,'' will\ngenerate appropriate entries into the general and module indexes.\nThe following macro can be used to control the generation of index\ndata, and should be used in the document preamble:\nThere are a number of macros that are useful for adding index\nentries for particular concepts, many of which are specific to\nprogramming languages or even Python.\nAdditional macros are provided which are useful for conveniently\ncreating general index entries which should appear at many places\nin the index by rotating a list of words. These are simple macros\nthat simply use \\index to build some number of index\nentries. Index entries build using these macros contain both\nprimary and secondary text.", "python_version": "2.1", "length": 1696, "url": "https://docs.python.org/2.0/doc/indexing.html"}
{"title": "5.3 Information Units", "text": "meta-info.html | node8.html | node12.html | Documenting Python | contents.html\n---\n## 5.3 Information Units\nXXX Explain terminology, or come up with something more ``lay.''\nThere are a number of environments used to describe specific\nfeatures provided by modules. Each environment requires\nparameters needed to provide basic information about what is being\ndescribed, and the environment content should be the description.\nMost of these environments make entries in the general index (if\none is being produced for the document); if no index entry is\ndesired, non-indexing variants are available for many of these\nenvironments. The environments have names of the form\n`feature desc`, and the non-indexing variants are named\n`feature descni`. The available variants are explicitly\nincluded in the list below.\nFor each of these environments, the first parameter, name,\nprovides the name by which the feature is accessed.\nEnvironments which describe features of objects within a module,\nsuch as object methods or data attributes, allow an optional\ntype name parameter. When the feature is an attribute of\nclass instances, type name only needs to be given if the\nclass was not the most recently described class in the module; the\nname value from the most recent \\classdesc is implied.\nFor features of built-in or extension types, the type name\nvalue should always be provided. Another special case includes\nmethods and members of general ``protocols,'' such as the\nformatter and writer protocols described for the\nformatter module: these may be documented without any\nspecific implementation classes, and will always require the\ntype name parameter to be provided.", "python_version": "2.1", "length": 1659, "url": "https://docs.python.org/2.0/doc/info-units.html"}
{"title": "3 LATEX Primer", "text": "node3.html | doc.html | node5.html | Documenting Python | contents.html\n---\n# 3 LATEX Primer\nThis section is a brief introduction to LATEX concepts and\nsyntax, to provide authors enough information to author documents\nproductively without having to become ``TEXnicians.''\nPerhaps the most important concept to keep in mind while marking up\nPython documentation is that while TEX is unstructured, LATEX was\ndesigned as a layer on top of TEX which specifically supports\nstructured markup. The Python-specific markup is intended to extend\nthe structure provided by standard LATEX document classes to\nsupport additional information specific to Python.\nLATEX documents contain two parts: the preamble and the body.\nThe preamble is used to specify certain metadata about the document\nitself, such as the title, the list of authors, the date, and the\nclass the document belongs to. Additional information used\nto control index generation and the use of bibliographic databases\ncan also be placed in the preamble. For most authors, the preamble\ncan be most easily created by copying it from an existing document\nand modifying a few key pieces of information.\nThe class of a document is used to place a document within a\nbroad category of documents and set some fundamental formatting\nproperties. For Python documentation, two classes are used: the\n`manual` class and the `howto` class. These classes also\ndefine the additional markup used to document Python concepts and\nstructures. Specific information about these classes is provided in\nsection 4 (classes.html#classes), ``Document Classes,'' below. The first thing\nin the preamble is the declaration of the document's class.\nAfter the class declaration, a number of macros are used to\nprovide further information about the document and setup any\nadditional markup that is needed. No output is generated from the\npreamble; it is an error to include free text in the preamble\nbecause it would cause output.\nThe document body follows the preamble. This contains all the\nprinted components of the document marked up structurally. Generic\nLATEX structures include hierarchical sections", "python_version": "2.1", "length": 2125, "url": "https://docs.python.org/2.0/doc/latex-primer.html"}
{"title": "5.2 Meta-information Markup", "text": "preamble-info.html | node8.html | info-units.html | Documenting Python | contents.html\n---\n## 5.2 Meta-information Markup", "python_version": "2.1", "length": 121, "url": "https://docs.python.org/2.0/doc/meta-info.html"}
{"title": "5.4 Showing Code Examples", "text": "info-units.html | node8.html | node13.html | Documenting Python | contents.html\n---\n## 5.4 Showing Code Examples\nExamples of Python source code or interactive sessions are\nrepresented as \\verbatim environments. This environment\nis a standard part of LATEX. It is important to only use\nspaces for indentation in code examples since TEX drops tabs\ninstead of converting them to spaces.\nRepresenting an interactive session requires including the prompts\nand output along with the Python code. No special markup is\nrequired for interactive sessions. After the last line of input\nor output presented, there should not be an ``unused'' primary\nprompt; this is an example of what not to do:\n```text\n\n>>> 1 + 1\n2\n>>>\n```\nWithin the \\verbatim environment, characters special to\nLATEX do not need to be specially marked in any way. The entire\nexample will be presented in a monospaced font; no attempt at\n``pretty-printing'' is made, as the environment must work for\nnon-Python code and non-code displays. There should be no blank\nlines at the top or bottom of any \\verbatim display.\nThe Python Documentation Special Interest Group has discussed a\nnumber of approaches to creating pretty-printed code displays and\ninteractive sessions; see the Doc-SIG area on the Python Web site\nfor more information on this topic.", "python_version": "2.1", "length": 1305, "url": "https://docs.python.org/2.0/doc/node12.html"}
{"title": "5.5 Inline Markup", "text": "node12.html | node8.html | node14.html | Documenting Python | contents.html\n---\n## 5.5 Inline Markup\nThe macros described in this section are used to mark just about\nanything interesting in the document text. They may be used in\nheadings (though anything involving hyperlinks should be avoided\nthere) as well as in the body text.", "python_version": "2.1", "length": 329, "url": "https://docs.python.org/2.0/doc/node13.html"}
{"title": "5.6 Module-specific Markup", "text": "node13.html | node8.html | node15.html | Documenting Python | contents.html\n---\n## 5.6 Module-specific Markup\nThe markup described in this section is used to provide information\nabout a module being documented. A typical use of this markup\nappears at the top of the section used to document a module. A\ntypical example might look like this:\n```text\n\n\\section{\\module{spam} ---\nAccess to the SPAM facility}\n\n\\declaremodule{extension}{spam}\n\\platform{Unix}\n\\modulesynopsis{Access to the SPAM facility of \\UNIX{}.}\n\\moduleauthor{Jane Doe}{jane.doe@frobnitz.org}\n```\nPython packages-- collections of modules that can\nbe described as a unit -- are documented using the same markup as\nmodules. The name for a module in a package should be typed in\n``fully qualified'' form (i.e., it should include the package name).\nFor example, a module ``foo'' in package ``bar'' should be marked as\n\"\\module{bar.foo}\", and the beginning of the reference\nsection would appear as:\n```text\n\n\\section{\\module{bar.foo} ---\nModule from the \\module{bar} package}\n\n\\declaremodule{extension}{bar.foo}\n\\modulesynopsis{Nifty module from the \\module{bar} package.}\n\\moduleauthor{Jane Doe}{jane.doe@frobnitz.org}\n```\nNote that the name of a package is also marked using\n\\module.", "python_version": "2.1", "length": 1246, "url": "https://docs.python.org/2.0/doc/node14.html"}
{"title": "5.7 Library-level Markup", "text": "node14.html | node8.html | node16.html | Documenting Python | contents.html\n---\n## 5.7 Library-level Markup\nThis markup is used when describing a selection of modules. For\nexample, the Macintosh Library\nModules (../mac/mac.html) document uses this to help provide an overview of the\nmodules in the collection, and many chapters in the\nPython Library Reference (../lib/lib.html) use it for\nthe same purpose.", "python_version": "2.1", "length": 406, "url": "https://docs.python.org/2.0/doc/node15.html"}
{"title": "5.8 Table Markup", "text": "node15.html | node8.html | references.html | Documenting Python | contents.html\n---\n## 5.8 Table Markup\nThere are three general-purpose table environments defined which\nshould be used whenever possible. These environments are defined\nto provide tables of specific widths and some convenience for\nformatting. These environments are not meant to be general\nreplacements for the standard LATEX table environments, but can\nbe used for an advantage when the documents are processed using\nthe tools for Python documentation processing. In particular, the\ngenerated HTML looks good! There is also an advantage for the\neventual conversion of the documentation to SGML (see section\n8 (futures.html#futures), ``Future Directions'').\nEach environment is named \\tablecols, where cols\nis the number of columns in the table specified in lower-case\nRoman numerals. Within each of these environments, an additional\nmacro, \\linecols, is defined, where cols\nmatches the cols value of the corresponding table\nenvironment. These are supported for cols values of\n`ii`, `iii`, and `iv`. These environments are all\nbuilt on top of the \\tabular environment. Variants based on\nthe \\longtable environment are also provided.\nNote that all tables in the standard Python documentation use\nvertical lines between columns, and this must be specified in the\nmarkup for each table. A general border around the outside of the\ntable is not used, but would be the responsibility of the\nprocessor; the document markup should not include an exterior\nborder.\nThe \\longtable-based variants of the table environments are\nformatted with extra space before and after, so should only be\nused on tables which are long enough that splitting over multiple\npages is reasonable; tables with fewer than twenty rows should\nnever by marked using the long flavors of the table environments.\nThe header row is repeated across the top of each part of the\ntable.\nAn additional table-like environment is \\synopsistable. The\ntable generated by this environment contains two columns, and each\nrow is defined by an alternate definition of\n\\modulesynopsis. This environment is not normally used by\nauthors, but is created by the \\localmoduletable macro.", "python_version": "2.1", "length": 2192, "url": "https://docs.python.org/2.0/doc/node16.html"}
{"title": "6 Special Names", "text": "indexing.html | doc.html | node20.html | Documenting Python | contents.html\n---\n# 6 Special Names\nMany special names are used in the Python documentation, including\nthe names of operating systems, programming languages, standards\nbodies, and the like. Many of these were assigned LATEX macros\nat some point in the distant past, and these macros lived on long\npast their usefulness. In the current markup, these entities are\nnot assigned any special markup, but the preferred spellings are\ngiven here to aid authors in maintaining the consistency of\npresentation in the Python documentation.\nPOSIX: The name assigned to a particular group of standards. This is\nalways uppercase.\nPython: The name of our favorite programming language is always\ncapitalized.\nUnicode: The name of a character set and matching encoding. This is\nalways written capitalized.", "python_version": "2.1", "length": 850, "url": "https://docs.python.org/2.0/doc/node19.html"}
{"title": "1 Introduction", "text": "contents.html | doc.html | node3.html | Documenting Python | contents.html\n---\n# 1 Introduction\nPython's documentation has long been considered to be good for a\nfree programming language. There are a number of reasons for this,\nthe most important being the early commitment of Python's creator,\nGuido van Rossum, to providing documentation on the language and its\nlibraries, and the continuing involvement of the user community in\nproviding assistance for creating and maintaining documentation.\nThe involvement of the community takes many forms, from authoring to\nbug reports to just plain complaining when the documentation could\nbe more complete or easier to use. All of these forms of input from\nthe community have proved useful during the time I've been involved\nin maintaining the documentation.\nThis document is aimed at authors and potential authors of\ndocumentation for Python. More specifically, it is for people\ncontributing to the standard documentation and developing additional\ndocuments using the same tools as the standard documents. This\nguide will be less useful for authors using the Python documentation\ntools for topics other than Python, and less useful still for\nauthors not using the tools at all.\nThe material in this guide is intended to assist authors using the\nPython documentation tools. It includes information on the source\ndistribution of the standard documentation, a discussion of the\ndocument types, reference material on the markup defined in the\ndocument classes, a list of the external tools needed for processing\ndocuments, and reference material on the tools provided with the\ndocumentation resources. At the end, there is also a section\ndiscussing future directions for the Python documentation and where\nto turn for more information.", "python_version": "2.1", "length": 1775, "url": "https://docs.python.org/2.0/doc/node2.html"}
{"title": "7 Processing Tools", "text": "node19.html | doc.html | node21.html | Documenting Python | contents.html\n---\n# 7 Processing Tools", "python_version": "2.1", "length": 98, "url": "https://docs.python.org/2.0/doc/node20.html"}
{"title": "7.1 External Tools", "text": "node20.html | node20.html | node22.html | Documenting Python | contents.html\n---\n## 7.1 External Tools\nMany tools are needed to be able to process the Python\ndocumentation if all supported formats are required. This\nsection lists the tools used and when each is required. Consult\nthe Doc/README file to see if there are specific version\nrequirements for any of these.\ndvips: This program is a typical part of TEX installations. It is\nused to generate PostScript from the ``device independent''\n.dvi files. It is needed for the conversion to\nPostScript.\nemacs: Emacs is the kitchen sink of programmers' editors, and a damn\nfine kitchen sink it is. It also comes with some of the\nprocessing needed to support the proper menu structures for\nTexinfo documents when an info conversion is desired. This is\nneeded for the info conversion. Using xemacs\ninstead of FSF emacs may lead to instability in the\nconversion, but that's because nobody seems to maintain the\nEmacs Texinfo code in a portable manner.\nlatex: This is a world-class typesetter by Donald Knuth. It is used\nfor the conversion to PostScript, and is needed for the HTML\nconversion as well (LATEX2HTML requires one of the\nintermediate files it creates).\nlatex2html: Probably the longest Perl script anyone ever attempted to\nmaintain. This converts LATEX documents to HTML documents,\nand does a pretty reasonable job. It is required for the\nconversions to HTML and GNU info.\nlynx: This is a text-mode Web browser which includes an\nHTML-to-plain text conversion. This is used to convert\n`howto` documents to text.\nmake: Just about any version should work for the standard documents,\nbut GNU make is required for the experimental\nprocesses in Doc/tools/sgmlconv/, at least while\nthey're experimental.\nmakeindex: This is a standard program for converting LATEX index data\nto a formatted index; it should be included with all LATEX\ninstallations. It is needed for the PDF and PostScript\nconversions.\nmakeinfo: GNU makeinfo is used to convert Texinfo documents to\nGNU info files. Since Texinfo is used as an intermediate\nformat in the info conversion, this program is needed in that\nconversion.\npdflatex: pdfTEX is a relatively new variant of TEX, and is used to\ngenerate the PDF version of the manuals. It is typically\ninstalled as part of most of the large TEX distributions.\npdflatex is pdfTEX using the LATEX format.\nperl: Perl is required for LATEX2HTML and one of the scripts used\nto post-process LATEX2HTML output, as well as the\nHTML-to-Texinfo conversion. This is required for\nthe HTML and GNU info conversions.\npython: Python is used for many of the scripts in the\nDoc/tools/ directory; it is required for all\nconversions. This shouldn't be a problem if you're interested\nin writing documentation for Python!", "python_version": "2.1", "length": 2768, "url": "https://docs.python.org/2.0/doc/node21.html"}
{"title": "7.2 Internal Tools", "text": "node21.html | node20.html | futures.html | Documenting Python | contents.html\n---\n## 7.2 Internal Tools\nThis section describes the various scripts that are used to\nimplement various stages of document processing or to orchestrate\nentire build sequences. Most of these tools are only useful\nin the context of building the standard documentation, but some\nare more general.\nmkhowto: This is the primary script used to format third-party\ndocuments. It contains all the logic needed to ``get it\nright.'' The proper way to use this script is to make a\nsymbolic link to it or run it in place; the actual script file\nmust be stored as part of the documentation source tree,\nthough it may be used to format documents outside the\ntree. Use mkhowto --help\nfor a list of\ncommand line options.\nmkhowto can be used for both `howto` and\n`manual` class documents. (For the later, be sure to get\nthe latest version from the Python CVS repository rather than\nthe version distributed in the latex-1.5.2.tgz source\narchive.)\nXXX Need more here.", "python_version": "2.1", "length": 1025, "url": "https://docs.python.org/2.0/doc/node22.html"}
{"title": "2 Directory Structure", "text": "node2.html | doc.html | latex-primer.html | Documenting Python | contents.html\n---\n# 2 Directory Structure\nThe source distribution for the standard Python documentation\ncontains a large number of directories. While third-party documents\ndo not need to be placed into this structure or need to be placed\nwithin a similar structure, it can be helpful to know where to look\nfor examples and tools when developing new documents using the\nPython documentation tools. This section describes this directory\nstructure.\nThe documentation sources are usually placed within the Python\nsource distribution as the top-level directory Doc/, but\nare not dependent on the Python source distribution in any way.\nThe Doc/ directory contains a few files and several\nsubdirectories. The files are mostly self-explanatory, including a\nREADME and a Makefile. The directories fall into\nthree categories:", "python_version": "2.1", "length": 880, "url": "https://docs.python.org/2.0/doc/node3.html"}
{"title": "3.1 Syntax", "text": "latex-primer.html | latex-primer.html | node6.html | Documenting Python | contents.html\n---\n## 3.1 Syntax\nThere are a things that an author of Python documentation needs to\nknow about LATEX syntax.\nA comment is started by the ``percent'' character\n(\"%\") and continues through the end of the line and all\nleading whitespace on the following line. This is a little\ndifferent from any programming language I know of, so an example\nis in order:\n```text\n\nThis is text.% comment\nThis is more text. % another comment\nStill more text.\n```\nThe first non-comment character following the first comment is the\nletter \"T\" on the second line; the leading whitespace on\nthat line is consumed as part of the first comment. This means\nthat there is no space between the first and second sentences, so\nthe period and letter \"T\" will be directly adjacent in\nthe typeset document.\nNote also that though the first non-comment character after the\nsecond comment is the letter \"S\", there is whitespace\npreceding the comment, so the two sentences are separated as\nexpected.\nA group is an enclosure for a collection of text and\ncommands which encloses the formatting context and constrains the\nscope of any changes to that context made by commands within the\ngroup. Groups can be nested hierarchically. The formatting\ncontext includes the font and the definition of additional macros\n(or overrides of macros defined in outer groups). Syntactically,\ngroups are enclosed in braces:\n```text\n\n{text in a group}\n```\nAn alternate syntax for a group using brackets (`[...]`) is\nused by macros and environment constructors which take optional\nparameters; brackets do not normally hold syntactic significance.\nA degenerate group, containing only one atomic bit of content,\ndoes not need to have an explicit group, unless it is required to\navoid ambiguity. Since Python tends toward the explicit, groups\nare also made explicit in the documentation markup.\nGroups are used only sparingly in the Python documentation, except\nfor their use in marking parameters to macros and environments.\nA macro is usually simple construct which is identified by\nname and can take some number of parameters. In normal LATEX\nusage, one of these can be optional. The markup is introduced\nusing the backslash character (\"\\\"), and the name is\ngiven by alphabetic characters (no digits, hyphens, or\nunderscores). Required parameters should be marked as a group,\nand optional parameters should be marked using the alternate\nsyntax for a group.\nFor example, a macro named ``foo'' which takes a single parameter\nwould appear like this:\n```text\n\n\\name{parameter}\n```\nA macro which takes an optional parameter would be typed like this\nwhen the optional paramter is given:\n```text\n\n\\name[optional]\n```\nIf both optional and required parameters are to be required, it\nlooks like this:\n```text\n\n\\name[optional]{required}\n```\nA macro name may be followed by a space or newline; a space\nbetween the macro name and any parameters will be consumed, but\nthis usage is not practiced in the Python documentation. Such a\nspace is still consumed if there are no parameters to the marco,\nin which case inserting an empty group (`{}`) or explicit\nword space (\"\\ \") immediately after the macro name helps to\navoid running the expansion of the macro into the following text.\nMacros which take no parameters but which should not be followed\nby a word space do not need special treatment if the following\ncharacter in the document source if not a name character (such as\npuctuation).\nEach line of this example shows an appropriate way to write text\nwhich includes a macro which takes no parameters:\n```text\n\nThis \\UNIX{} is followed by a space.\nThis \\UNIX\\ is also followed by a space.\n\\UNIX, followed by a comma, needs no additional markup.\n```\nAn environment is a larger construct than a macro, and can\nbe used for things with more content that would conveniently fit\nin a macro parameter. They are primarily used when formatting\nparameters need to be changed before and after a large chunk of\ncontent, but the content itself needs to be highly flexible. Code\nsamples are presented using an environment, and descriptions of\nfunctions, methods, and classes are also marked using envionments.\nSince the content of an environment is free-form and can consist\nof several paragraphs, they are actually marked using a pair of\nmacros: \\begin and \\end. These macros both take the\nname of the environment as a parameter. An example is the\nenvironment used to mark the abstract of a document:\n```text\n\n\\begin{abstract}\nThis is the text of the abstract. It concisely explains what\ninformation is found in the document.\n\nIt can consist of multiple paragraphs.\n\\end{abstract}\n```\nAn environment can also have required and optional parameters of\nits own. These follow the parameter of the \\begin macro.\nThis example shows an environment which takes a single required\nparameter:\n```text\n\n\\begin{datadesc}{controlnames}\nA 33-element string array that contains the \\ASCII{} mnemonics for\nthe thirty-two \\ASCII{} control characters from 0 (NUL) to 0x1f\n(US), in order, plus the mnemonic \\samp{SP} for the space character.\n\\end{datadesc}\n```\nThere are a number of less-used marks in LATEX are used to\nenter non-ASCII characters, especially those used in European\nnames. Given that these are often used adjacent to other\ncharacters, the markup required to produce the proper character\nmay need to be followed by a space or an empty group, or the the\nmarkup can be enclosed in a group. Some which are found in Python\ndocumentation are:", "python_version": "2.1", "length": 5535, "url": "https://docs.python.org/2.0/doc/node5.html"}
{"title": "3.2 Hierarchical Structure", "text": "node5.html | latex-primer.html | classes.html | Documenting Python | contents.html\n---\n## 3.2 Hierarchical Structure\nLATEX expects documents to be arranged in a conventional,\nhierarchical way, with chapters, sections, sub-sections,\nappendixes, and the like. These are marked using macros rather\nthan environments, probably because the end of a section can be\nsafely inferred when a section of equal or higher level starts.\nThere are six ``levels'' of sectioning in the document classes\nused for Python documentation, and the lowest two levels are not\nused. The levels are:\nNotes:\n(1): Only used for the `manual` documents, as described in\nsection 4 (classes.html#classes), ``Document Classes.''\n(2): Not the same as a paragraph of text; nobody seems to use this.", "python_version": "2.1", "length": 762, "url": "https://docs.python.org/2.0/doc/node6.html"}
{"title": "5 Special Markup Constructs", "text": "classes.html | doc.html | preamble-info.html | Documenting Python | contents.html\n---\n# 5 Special Markup Constructs\nThe Python document classes define a lot of new environments and\nmacros. This section contains the reference material for these\nfacilities.", "python_version": "2.1", "length": 255, "url": "https://docs.python.org/2.0/doc/node8.html"}
{"title": "5.1 Markup for the Preamble", "text": "node8.html | node8.html | meta-info.html | Documenting Python | contents.html\n---\n## 5.1 Markup for the Preamble", "python_version": "2.1", "length": 112, "url": "https://docs.python.org/2.0/doc/preamble-info.html"}
{"title": "5.9 Reference List Markup", "text": "node16.html | node8.html | indexing.html | Documenting Python | contents.html\n---\n## 5.9 Reference List Markup\nMany sections include a list of references to module documentation\nor external documents. These lists are created using the\n\\seealso environment. This environment defines some\nadditional macros to support creating reference entries in a\nreasonable manner.\nThe \\seealso environment is typically placed in a section\njust before any sub-sections. This is done to ensure that\nreference links related to the section are not hidden in a\nsubsection in the hypertext renditions of the documentation.\nFor each of the following macros, why should be one or more\ncomplete sentences, starting with a capital letter (unless it\nstarts with an identifier, which should not be modified), and\nending with the apropriate punctuation.\nThese macros are only defined within the content of the\n\\seealso environment.", "python_version": "2.1", "length": 904, "url": "https://docs.python.org/2.0/doc/references.html"}
{"title": "8.1 Structured Documentation", "text": "futures.html | futures.html | discussion.html | Documenting Python | contents.html\n---\n## 8.1 Structured Documentation\nMost of the small changes to the LATEX markup have been made\nwith an eye to divorcing the markup from the presentation, making\nboth a bit more maintainable. Over the course of 1998, a large\nnumber of changes were made with exactly this in mind; previously,\nchanges had been made but in a less systematic manner and with\nmore concern for not needing to update the existing content. The\nresult has been a highly structured and semantically loaded markup\nlanguage implemented in LATEX. With almost no basic TEX or\nLATEX markup in use, however, the markup syntax is about the\nonly evidence of LATEX in the actual document sources.\nOne side effect of this is that while we've been able to use\nstandard ``engines'' for manipulating the documents, such as\nLATEX and LATEX2HTML, most of the actual transformations have\nbeen created specifically for Python. The LATEX document\nclasses and LATEX2HTML support are both complete implementations\nof the specific markup designed for these documents.\nCombining highly customized markup with the somewhat esoteric\nsystems used to process the documents leads us to ask some\nquestions: Can we do this more easily? and, Can we do this\nbetter? After a great deal of discussion with the community, we\nhave determined that actively pursuing modern structured\ndocumentation systems is worth some investment of time.\nThere appear to be two real contenders in this arena: the Standard\nGeneral Markup Language (SGML), and the Extensible Markup Language\n(XML). Both of these standards have advantages and disadvantages,\nand many advantages are shared.\nSGML offers advantages which may appeal most to authors,\nespecially those using ordinary text editors. There are also\nadditional abilities to define content models. A number of\nhigh-quality tools with demonstrated maturity is available, but\nmost are not free; for those which are, portability issues remain\na problem.\nThe advantages of XML include the availability of a large number\nof evolving tools. Unfortunately, many of the associated\nstandards are still evolving, and the tools will have to follow\nalong. This means that developing a robust tool set that uses\nmore than the basic XML 1.0 recommendation is not possible in the\nshort term. The promised availability of a wide variety of\nhigh-quality tools which support some of the most important\nrelated standards is not immediate. Many tools are likely to be\nfree.\nXXX Eventual migration to SGML/XML.", "python_version": "2.1", "length": 2550, "url": "https://docs.python.org/2.0/doc/structured.html"}
{"title": "About this document ...", "text": "reporting-bugs.html | ext.html | Extending and Embedding the Python Interpreter | contents.html\n---\n# About this document ...\nExtending and Embedding the Python Interpreter,\nApril 15, 2001, Release 2.1\nThis document was generated using the LaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) translator.\nLaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) is Copyright ©\n1993, 1994, 1995, 1996, 1997, Nikos\nDrakos (http://cbl.leeds.ac.uk/nikos/personal.html), Computer Based Learning Unit, University of\nLeeds, and Copyright © 1997, 1998, Ross\nMoore (http://www.maths.mq.edu.au/~ross/), Mathematics Department, Macquarie University,\nSydney.\nThe application of LaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) to the Python\ndocumentation has been heavily tailored by Fred L. Drake,\nJr. Original navigation icons were contributed by Christopher\nPetrilli.\n---\n## Comments and Questions\nGeneral comments and questions regarding this document should\nbe sent by email to python-docs@python.org (mailto:python-docs@python.org). If you find specific errors in\nthis document, please report the bug at the Python Bug\nTracker (http://sourceforge.net/bugs/?group_id=5470) at SourceForge (http://sourceforge.net/).\nQuestions regarding how to use the information in this\ndocument should be sent to the Python news group, comp.lang.python (news:comp.lang.python), or the Python mailing list (http://www.python.org/mailman/listinfo/python-list) (which is gated to the newsgroup and\ncarries the same content).\nFor any of these channels, please be sure not to send HTML email.\nThanks.\n---\nreporting-bugs.html | ext.html | Extending and Embedding the Python Interpreter | contents.html\n---\nRelease 2.1, documentation updated on April 15, 2001.", "python_version": "2.1", "length": 1748, "url": "https://docs.python.org/2.0/ext/about.html"}
{"title": "1.3 Back to the Example", "text": "errors.html | intro.html | methodTable.html | Extending and Embedding the Python Interpreter | contents.html\n---\n# 1.3 Back to the Example\nGoing back to our example function, you should now be able to\nunderstand this statement:\n```text\n\nif (!PyArg_ParseTuple(args, \"s\", &command))\nreturn NULL;\n```\nIt returns NULL (the error indicator for functions returning\nobject pointers) if an error is detected in the argument list, relying\non the exception set by PyArg_ParseTuple(). Otherwise the\nstring value of the argument has been copied to the local variable\ncommand. This is a pointer assignment and you are not supposed\nto modify the string to which it points (so in Standard C, the variable\ncommand should properly be declared as \"const char\n*command\").\nThe next statement is a call to the Unix function\nsystem(), passing it the string we just got from\nPyArg_ParseTuple():\n```text\n\nsts = system(command);\n```\nOur spam.system() function must return the value of\nsts as a Python object. This is done using the function\nPy_BuildValue(), which is something like the inverse of\nPyArg_ParseTuple(): it takes a format string and an\narbitrary number of C values, and returns a new Python object.\nMore info on Py_BuildValue() is given later.\n```text\n\nreturn Py_BuildValue(\"i\", sts);\n```\nIn this case, it will return an integer object. (Yes, even integers\nare objects on the heap in Python!)\nIf you have a C function that returns no useful argument (a function\nreturning void), the corresponding Python function must return\n`None`. You need this idiom to do so:\n```text\n\nPy_INCREF(Py_None);\nreturn Py_None;\n```\nPy_None is the C name for the special Python object\n`None`. It is a genuine Python object rather than a NULL\npointer, which means ``error'' in most contexts, as we have seen.", "python_version": "2.1", "length": 1774, "url": "https://docs.python.org/2.0/ext/backToExample.html"}
{"title": "3. Building C and C++ Extensions on Unix", "text": "dnt-type-methods.html | ext.html | custom-interps.html | Extending and Embedding the Python Interpreter | contents.html\n---\n# 3. Building C and C++ Extensions on Unix\nStarting in Python 1.4, Python provides a special make file for\nbuilding make files for building dynamically-linked extensions and\ncustom interpreters. The make file make file builds a make file\nthat reflects various system variables determined by configure when\nthe Python interpreter was built, so people building module's don't\nhave to resupply these settings. This vastly simplifies the process\nof building extensions and custom interpreters on Unix systems.\nThe make file make file is distributed as the file\nMisc/Makefile.pre.in in the Python source distribution. The\nfirst step in building extensions or custom interpreters is to copy\nthis make file to a development directory containing extension module\nsource.\nThe make file make file, Makefile.pre.in uses metadata\nprovided in a file named Setup. The format of the Setup\nfile is the same as the Setup (or Setup.dist) file\nprovided in the Modules/ directory of the Python source\ndistribution. The Setup file contains variable definitions:\n```text\n\nEC=/projects/ExtensionClass\n```\nand module description lines. It can also contain blank lines and\ncomment lines that start with \"#\".\nA module description line includes a module name, source files,\noptions, variable references, and other input files, such\nas libraries or object files. Consider a simple example:\n```text\n\nExtensionClass ExtensionClass.c\n```\nThis is the simplest form of a module definition line. It defines a\nmodule, ExtensionClass, which has a single source file,\nExtensionClass.c.\nThis slightly more complex example uses an -I option to\nspecify an include directory:\n```text\n\nEC=/projects/ExtensionClass\ncPersistence cPersistence.c -I$(EC)\n```\nThis example also illustrates the format for variable references.\nFor systems that support dynamic linking, the Setup file should\nbegin:\n```text\n\n*shared*\n```\nto indicate that the modules defined in Setup are to be built\nas dynamically linked modules. A line containing only \"*static*\"can be used to indicate the subsequently listed modules should be\nstatically linked.\nHere is a complete Setup file for building a\ncPersistent module:\n```text\n\n# Set-up file to build the cPersistence module.\n# Note that the text should begin in the first column.\n*shared*\n\n# We need the path to the directory containing the ExtensionClass\n# include file.\nEC=/projects/ExtensionClass\ncPersistence cPersistence.c -I$(EC)\n```\nAfter the Setup file has been created, Makefile.pre.in\nis run with the \"boot\" target to create a make file:\n```text\n\nmake -f Makefile.pre.in boot\n```\nThis creates the file, Makefile. To build the extensions, simply\nrun the created make file:\n```text\n\nmake\n```\nIt's not necessary to re-run Makefile.pre.in if the\nSetup file is changed. The make file automatically rebuilds\nitself if the Setup file changes.", "python_version": "2.1", "length": 2948, "url": "https://docs.python.org/2.0/ext/building-on-unix.html"}
{"title": "4. Building C and C++ Extensions on Windows", "text": "distributing.html | ext.html | win-cookbook.html | Extending and Embedding the Python Interpreter | contents.html\n---\n# 4. Building C and C++ Extensions on Windows\nThis chapter briefly explains how to create a Windows extension module\nfor Python using Microsoft Visual C++, and follows with more\ndetailed background information on how it works. The explanatory\nmaterial is useful for both the Windows programmer learning to build\nPython extensions and the Unix programmer interested in producing\nsoftware which can be successfully built on both Unix and Windows.", "python_version": "2.1", "length": 562, "url": "https://docs.python.org/2.0/ext/building-on-windows.html"}
{"title": "1.9 Building Arbitrary Values", "text": "parseTupleAndKeywords.html | intro.html | refcounts.html | Extending and Embedding the Python Interpreter | contents.html\n---\n# 1.9 Building Arbitrary Values\nThis function is the counterpart to PyArg_ParseTuple(). It is\ndeclared as follows:\n```text\n\nPyObject *Py_BuildValue(char *format, ...);\n```\nIt recognizes a set of format units similar to the ones recognized by\nPyArg_ParseTuple(), but the arguments (which are input to the\nfunction, not output) must not be pointers, just values. It returns a\nnew Python object, suitable for returning from a C function called\nfrom Python.\nOne difference with PyArg_ParseTuple(): while the latter\nrequires its first argument to be a tuple (since Python argument lists\nare always represented as tuples internally),\nPy_BuildValue() does not always build a tuple. It builds\na tuple only if its format string contains two or more format units.\nIf the format string is empty, it returns `None`; if it contains\nexactly one format unit, it returns whatever object is described by\nthat format unit. To force it to return a tuple of size 0 or one,\nparenthesize the format string.\nWhen memory buffers are passed as parameters to supply data to build\nobjects, as for the \"s\" and \"s#\" formats, the required data\nis copied. Buffers provided by the caller are never referenced by the\nobjects created by Py_BuildValue(). In other words, if\nyour code invokes malloc() and passes the allocated memory\nto Py_BuildValue(), your code is responsible for\ncalling free() for that memory once\nPy_BuildValue() returns.\nIn the following description, the quoted form is the format unit; the\nentry in (round) parentheses is the Python object type that the format\nunit will return; and the entry in [square] brackets is the type of\nthe C value(s) to be passed.\nThe characters space, tab, colon and comma are ignored in format\nstrings (but not within format units such as \"s#\"). This can be\nused to make long format strings a tad more readable.\n\"s\" (string) [char *]: Convert a null-terminated C string to a Python object. If the C\nstring pointer is NULL, `None` is used.\n\"s#\" (string) [char *, int]: Convert a C string and its length to a Python object. If the C string\npointer is NULL, the length is ignored and `None` is\nreturned.\n\"z\" (string or `None`) [char *]: Same as \"s\".\n\"z#\" (string or `None`) [char *, int]: Same as \"s#\".\n\"u\" (Unicode string) [Py_UNICODE *]: Convert a null-terminated buffer of Unicode (UCS-2) data to a Python\nUnicode object. If the Unicode buffer pointer is NULL,\n`None` is returned.\n\"u#\" (Unicode string) [Py_UNICODE *, int]: Convert a Unicode (UCS-2) data buffer and its length to a Python\nUnicode object. If the Unicode buffer pointer is NULL, the length\nis ignored and `None` is returned.\n\"i\" (integer) [int]: Convert a plain C int to a Python integer object.\n\"b\" (integer) [char]: Same as \"i\".\n\"h\" (integer) [short int]: Same as \"i\".\n\"l\" (integer) [long int]: Convert a C long int to a Python integer object.\n\"c\" (string of length 1) [char]: Convert a C int representing a character to a Python string of\nlength 1.\n\"d\" (float) [double]: Convert a C double to a Python floating point number.\n\"f\" (float) [float]: Same as \"d\".\n\"D\" (complex) [Py_complex *]: Convert a C Py_complex structure to a Python complex number.\n\"O\" (object) [PyObject *]: Pass a Python object untouched (except for its reference count, which\nis incremented by one). If the object passed in is a NULL\npointer, it is assumed that this was caused because the call producing\nthe argument found an error and set an exception. Therefore,\nPy_BuildValue() will return NULL but won't raise an\nexception. If no exception has been raised yet,\nPyExc_SystemError is set.\n\"S\" (object) [PyObject *]: Same as \"O\".\n\"U\" (object) [PyObject *]: Same as \"O\".\n\"N\" (object) [PyObject *]: Same as \"O\", except it doesn't increment the reference count on\nthe object. Useful when the object is created by a call to an object\nconstructor in the argument list.\n\"O&\" (object) [converter, anything]: Convert anything to a Python object through a converter\nfunction. The function is called with anything (which should be\ncompatible with void *) as its argument and should return a\n``new'' Python object, or NULL if an error occurred.\n\"(items)\" (tuple) [matching-items]: Convert a sequence of C values to a Python tuple with the same number\nof items.\n\"[items]\" (list) [matching-items]: Convert a sequence of C values to a Python list with the same number\nof items.\n\"{items}\" (dictionary) [matching-items]: Convert a sequence of C values to a Python dictionary. Each pair of\nconsecutive C values adds one item to the dictionary, serving as key\nand value, respectively.\nIf there is an error in the format string, the\nPyExc_SystemError exception is raised and NULL returned.\nExamples (to the left the call, to the right the resulting Python value):\n```text\n\nPy_BuildValue(\"\") None\nPy_BuildValue(\"i\", 123) 123\nPy_BuildValue(\"iii\", 123, 456, 789) (123, 456, 789)\nPy_BuildValue(\"s\", \"hello\") 'hello'\nPy_BuildValue(\"ss\", \"hello\", \"world\") ('hello', 'world')\nPy_BuildValue(\"s#\", \"hello\", 4) 'hell'\nPy_BuildValue(\"()\") ()\nPy_BuildValue(\"(i)\", 123) (123,)\nPy_BuildValue(\"(ii)\", 123, 456) (123, 456)\nPy_BuildValue(\"(i,i)\", 123, 456) (123, 456)\nPy_BuildValue(\"[i,i]\", 123, 456) [123, 456]\nPy_BuildValue(\"{s:i,s:i}\",\n\"abc\", 123, \"def\", 456) {'abc': 123, 'def': 456}\nPy_BuildValue(\"((ii)(ii)) (ii)\",\n1, 2, 3, 4, 5, 6) (((1, 2), (3, 4)), (5, 6))\n```", "python_version": "2.1", "length": 5417, "url": "https://docs.python.org/2.0/ext/buildValue.html"}
{"title": "1.6 Calling Python Functions from C", "text": "compilation.html | intro.html | parseTuple.html | Extending and Embedding the Python Interpreter | contents.html\n---\n# 1.6 Calling Python Functions from C\nSo far we have concentrated on making C functions callable from\nPython. The reverse is also useful: calling Python functions from C.\nThis is especially the case for libraries that support so-called\n``callback'' functions. If a C interface makes use of callbacks, the\nequivalent Python often needs to provide a callback mechanism to the\nPython programmer; the implementation will require calling the Python\ncallback functions from a C callback. Other uses are also imaginable.\nFortunately, the Python interpreter is easily called recursively, and\nthere is a standard interface to call a Python function. (I won't\ndwell on how to call the Python parser with a particular string as\ninput -- if you're interested, have a look at the implementation of\nthe -c command line option in Python/pythonmain.c\nfrom the Python source code.)\nCalling a Python function is easy. First, the Python program must\nsomehow pass you the Python function object. You should provide a\nfunction (or some other interface) to do this. When this function is\ncalled, save a pointer to the Python function object (be careful to\nPy_INCREF() it!) in a global variable -- or wherever you\nsee fit. For example, the following function might be part of a module\ndefinition:\n```text\n\nstatic PyObject *my_callback = NULL;\n\nstatic PyObject *\nmy_set_callback(dummy, args)\nPyObject *dummy, *args;\n{\nPyObject *result = NULL;\nPyObject *temp;\n\nif (PyArg_ParseTuple(args, \"O:set_callback\", &temp)) {\nif (!PyCallable_Check(temp)) {\nPyErr_SetString(PyExc_TypeError, \"parameter must be callable\");\nreturn NULL;\n}\nPy_XINCREF(temp); /* Add a reference to new callback */\nPy_XDECREF(my_callback); /* Dispose of previous callback */\nmy_callback = temp; /* Remember new callback */\n/* Boilerplate to return \"None\" */\nPy_INCREF(Py_None);\nresult = Py_None;\n}\nreturn result;\n}\n```\nThis function must be registered with the interpreter using the\nMETH_VARARGS flag; this is described in section\n1.4 (methodTable.html#methodTable), ``The Module's Method Table and Initialization\nFunction.'' The PyArg_ParseTuple() function and its\narguments are documented in section 1.7 (parseTuple.html#parseTuple), ``Format Strings\nfor PyArg_ParseTuple().''\nThe macros Py_XINCREF() and Py_XDECREF()\nincrement/decrement the reference count of an object and are safe in\nthe presence of NULL pointers (but note that temp will not be\nNULL in this context). More info on them in section\n1.10 (refcounts.html#refcounts), ``Reference Counts.''\nLater, when it is time to call the function, you call the C function\nPyEval_CallObject(). This function has two arguments, both\npointers to arbitrary Python objects: the Python function, and the\nargument list. The argument list must always be a tuple object, whose\nlength is the number of arguments. To call the Python function with\nno arguments, pass an empty tuple; to call it with one argument, pass\na singleton tuple. Py_BuildValue() returns a tuple when its\nformat string consists of zero or more format codes between\nparentheses. For example:\n```text\n\nint arg;\nPyObject *arglist;\nPyObject *result;\n...\narg = 123;\n...\n/* Time to call the callback */\narglist = Py_BuildValue(\"(i)\", arg);\nresult = PyEval_CallObject(my_callback, arglist);\nPy_DECREF(arglist);\n```\nPyEval_CallObject() returns a Python object pointer: this is\nthe return value of the Python function. PyEval_CallObject() is\n``reference-count-neutral'' with respect to its arguments. In the\nexample a new tuple was created to serve as the argument list, which\nis Py_DECREF()-ed immediately after the call.\nThe return value of PyEval_CallObject() is ``new'': either it\nis a brand new object, or it is an existing object whose reference\ncount has been incremented. So, unless you want to save it in a\nglobal variable, you should somehow Py_DECREF() the result,\neven (especially!) if you are not interested in its value.\nBefore you do this, however, it is important to check that the return\nvalue isn't NULL. If it is, the Python function terminated by\nraising an exception. If the C code that called\nPyEval_CallObject() is called from Python, it should now\nreturn an error indication to its Python caller, so the interpreter\ncan print a stack trace, or the calling Python code can handle the\nexception. If this is not possible or desirable, the exception should\nbe cleared by calling PyErr_Clear(). For example:\n```text\n\nif (result == NULL)\nreturn NULL; /* Pass error back */\n...use result...\nPy_DECREF(result);\n```\nDepending on the desired interface to the Python callback function,\nyou may also have to provide an argument list to\nPyEval_CallObject(). In some cases the argument list is\nalso provided by the Python program, through the same interface that\nspecified the callback function. It can then be saved and used in the\nsame manner as the function object. In other cases, you may have to\nconstruct a new tuple to pass as the argument list. The simplest way\nto do this is to call Py_BuildValue(). For example, if\nyou want to pass an integral event code, you might use the following\ncode:\n```text\n\nPyObject *arglist;\n...\narglist = Py_BuildValue(\"(l)\", eventcode);\nresult = PyEval_CallObject(my_callback, arglist);\nPy_DECREF(arglist);\nif (result == NULL)\nreturn NULL; /* Pass error back */\n/* Here maybe use the result */\nPy_DECREF(result);\n```\nNote the placement of \"Py_DECREF(arglist)\" immediately after the\ncall, before the error check! Also note that strictly spoken this\ncode is not complete: Py_BuildValue() may run out of\nmemory, and this should be checked.", "python_version": "2.1", "length": 5650, "url": "https://docs.python.org/2.0/ext/callingPython.html"}
{"title": "1.5 Compilation and Linkage", "text": "methodTable.html | intro.html | callingPython.html | Extending and Embedding the Python Interpreter | contents.html\n---\n# 1.5 Compilation and Linkage\nThere are two more things to do before you can use your new extension:\ncompiling and linking it with the Python system. If you use dynamic\nloading, the details depend on the style of dynamic loading your\nsystem uses; see the chapters about building extension modules on\nUnix (chapter 3 (building-on-unix.html#building-on-unix)) and Windows (chapter\n4 (building-on-windows.html#building-on-windows)) for more information about this.\nIf you can't use dynamic loading, or if you want to make your module a\npermanent part of the Python interpreter, you will have to change the\nconfiguration setup and rebuild the interpreter. Luckily, this is\nvery simple: just place your file (spammodule.c for example) in\nthe Modules/ directory of an unpacked source distribution, add\na line to the file Modules/Setup.local describing your file:\n```text\n\nspam spammodule.o\n```\nand rebuild the interpreter by running make in the toplevel\ndirectory. You can also run make in the Modules/\nsubdirectory, but then you must first rebuild Makefile\nthere by running `make Makefile'. (This is necessary each\ntime you change the Setup file.)\nIf your module requires additional libraries to link with, these can\nbe listed on the line in the configuration file as well, for instance:\n```text\n\nspam spammodule.o -lX11\n```", "python_version": "2.1", "length": 1439, "url": "https://docs.python.org/2.0/ext/compilation.html"}
{"title": "Contents", "text": "front.html | ext.html | intro.html | Extending and Embedding the Python Interpreter\n---\n## Contents\nTable of Contents\n- Front Matter (front.html)\n 1. Extending Python with C or C++ (intro.html)\n - 1.1 A Simple Example (simpleExample.html)\n 1.2 Intermezzo: Errors and Exceptions (errors.html)\n 1.3 Back to the Example (backToExample.html)\n 1.4 The Module's Method Table and Initialization Function (methodTable.html)\n 1.5 Compilation and Linkage (compilation.html)\n 1.6 Calling Python Functions from C (callingPython.html)\n 1.7 Extracting Parameters in Extension Functions (parseTuple.html)\n 1.8 Keyword Parameters for Extension Functions (parseTupleAndKeywords.html)\n 1.9 Building Arbitrary Values (buildValue.html)\n 1.10 Reference Counts (refcounts.html)\n - 1.10.1 Reference Counting in Python (refcountsInPython.html)\n 1.10.2 Ownership Rules (ownershipRules.html)\n 1.10.3 Thin Ice (thinIce.html)\n 1.10.4 NULL Pointers (nullPointers.html)\n 1.11 Writing Extensions in C++ (cplusplus.html)\n 1.12 Providing a C API for an Extension Module (using-cobjects.html)\n 2. Defining New Types (defining-new-types.html)\n - 2.1 The Basics (dnt-basics.html)\n 2.2 Type Methods (dnt-type-methods.html)\n 3. Building C and C++ Extensions on Unix (building-on-unix.html)\n - 3.1 Building Custom Interpreters (custom-interps.html)\n 3.2 Module Definition Options (module-defn-options.html)\n 3.3 Example (module-defn-example.html)\n 3.4 Distributing your extension modules (distributing.html)\n 4. Building C and C++ Extensions on Windows (building-on-windows.html)\n - 4.1 A Cookbook Approach (win-cookbook.html)\n 4.2 Differences Between Unix and Windows (dynamic-linking.html)\n 4.3 Using DLLs in Practice (win-dlls.html)\n 5. Embedding Python in Another Application (embedding.html)\n - 5.1 Embedding Python in C++ (embeddingInCplusplus.html)\n 5.2 Linking Requirements (link-reqs.html)\n A. Reporting Bugs (reporting-bugs.html)\n About this document ... (about.html)\nEnd of Table of Contents", "python_version": "2.1", "length": 1997, "url": "https://docs.python.org/2.0/ext/contents.html"}
{"title": "1.11 Writing Extensions in C++", "text": "nullPointers.html | intro.html | using-cobjects.html | Extending and Embedding the Python Interpreter | contents.html\n---\n# 1.11 Writing Extensions in C++\nIt is possible to write extension modules in C++. Some restrictions\napply. If the main program (the Python interpreter) is compiled and\nlinked by the C compiler, global or static objects with constructors\ncannot be used. This is not a problem if the main program is linked\nby the C++ compiler. Functions that will be called by the\nPython interpreter (in particular, module initalization functions)\nhave to be declared using `extern \"C\"`.\nIt is unnecessary to enclose the Python header files in\n`extern \"C\" {...}` -- they use this form already if the symbol\n\"__cplusplus\" is defined (all recent C++ compilers define this\nsymbol).", "python_version": "2.1", "length": 783, "url": "https://docs.python.org/2.0/ext/cplusplus.html"}
{"title": "3.1 Building Custom Interpreters", "text": "building-on-unix.html | building-on-unix.html | module-defn-options.html | Extending and Embedding the Python Interpreter | contents.html\n---\n# 3.1 Building Custom Interpreters\nThe make file built by Makefile.pre.in can be run with the\n\"static\" target to build an interpreter:\n```text\n\nmake static\n```\nAny modules defined in the Setup file before the\n\"*shared*\" line will be statically linked into the interpreter.\nTypically, a \"*shared*\" line is omitted from the\nSetup file when a custom interpreter is desired.", "python_version": "2.1", "length": 512, "url": "https://docs.python.org/2.0/ext/custom-interps.html"}
{"title": "2. Defining New Types", "text": "using-cobjects.html | ext.html | dnt-basics.html | Extending and Embedding the Python Interpreter | contents.html\n---\n# 2. Defining New Types\nAs mentioned in the last chapter, Python allows the writer of an\nextension module to define new types that can be manipulated from\nPython code, much like strings and lists in core Python.\nThis is not hard; the code for all extension types follows a pattern,\nbut there are some details that you need to understand before you can\nget started.", "python_version": "2.1", "length": 482, "url": "https://docs.python.org/2.0/ext/defining-new-types.html"}
{"title": "3.4 Distributing your extension modules", "text": "module-defn-example.html | building-on-unix.html | building-on-windows.html | Extending and Embedding the Python Interpreter | contents.html\n---\n# 3.4 Distributing your extension modules\nThere are two ways to distribute extension modules for others to use.\nThe way that allows the easiest cross-platform support is to use the\ndistutilspackage. The manual\nDistributing Python Modules (../dist/dist.html) contains\ninformation on this approach. It is recommended that all new\nextensions be distributed using this approach to allow easy building\nand installation across platforms. Older extensions should migrate to\nthis approach as well.\nWhat follows describes the older approach; there are still many\nextensions which use this.\nWhen distributing your extension modules in source form, make sure to\ninclude a Setup file. The Setup file should be named\nSetup.in in the distribution. The make file make file,\nMakefile.pre.in, will copy Setup.in to Setup if\nthe person installing the extension doesn't do so manually.\nDistributing a Setup.in file makes it easy for people to\ncustomize the Setup file while keeping the original in\nSetup.in.\nIt is a good idea to include a copy of Makefile.pre.in for\npeople who do not have a source distribution of Python.\nDo not distribute a make file. People building your modules\nshould use Makefile.pre.in to build their own make file. A\nREADME file included in the package should provide simple\ninstructions to perform the build.", "python_version": "2.1", "length": 1460, "url": "https://docs.python.org/2.0/ext/distributing.html"}