{"title": "Extending and Embedding the Python Interpreter", "text": "---\nnode1.html node1.html\n---\n# Extending and Embedding the Python Interpreter\nGuido van Rossum\nDept. AA, CWI, P.O. Box 94079\n1090 GB Amsterdam, The Netherlands\nE-mail: guido@cwi.nl\n10 April 1995\nRelease 1.2\nCopyright © 1991-1995 by Stichting Mathematisch Centrum,\nAmsterdam, The Netherlands.\nAll 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 names of Stichting Mathematisch\nCentrum or CWI not be used in advertising or publicity pertaining to\ndistribution of the software without specific, written prior permission.\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:\nPython is an interpreted, object-oriented programming language. This\ndocument describes how to write modules in C or C++ to extend the\nPython interpreter with new modules. Those modules can define new\nfunctions but also new object types and their methods. The document\nalso describes how to embed the Python interpreter in another\napplication, for use as an extension language. Finally, it shows how\nto compile and link extension modules so that they can be loaded\ndynamically (at run time) into the interpreter, if the underlying\noperating system supports this feature.\nThis document assumes basic knowledge about Python. For an informal\nintroduction to the language, see the Python Tutorial. The Python\nReference Manual gives a more formal definition of the language. The\nPython Library Reference documents the existing object types,\nfunctions and modules (both built-in and written in Python) that give\nthe language its wide application range.\n---\n- Contents (node1.html#SECTION00100000000000000000)\nExtending Python with C or C++ code (node2.html#SECTION00200000000000000000)\n- Introduction (node3.html#SECTION00210000000000000000)\nA Simple Example (node4.html#SECTION00220000000000000000)\nIntermezzo: Errors and Exceptions (node5.html#SECTION00230000000000000000)\nBack to the Example (node6.html#SECTION00240000000000000000)\nThe Module's Method Table and Initialization Function (node7.html#SECTION00250000000000000000)\nCompilation and Linkage (node8.html#SECTION00260000000000000000)\nCalling Python Functions From C (node9.html#SECTION00270000000000000000)\nFormat Strings for PyArg_ParseTuple() (node10.html#SECTION00280000000000000000)\nThe Py_BuildValue() Function (node11.html#SECTION00290000000000000000)\nReference Counts (node12.html#SECTION002100000000000000000)\n- Introduction (node13.html#SECTION002101000000000000000)\nReference Counting in Python (node14.html#SECTION002102000000000000000)\nOwnership Rules (node15.html#SECTION002103000000000000000)\nThin Ice (node16.html#SECTION002104000000000000000)\nNULL Pointers (node17.html#SECTION002105000000000000000)\nWriting Extensions in C++ (node18.html#SECTION002110000000000000000)\nEmbedding Python in another application (node19.html#SECTION00300000000000000000)\n- Embedding Python in C++ (node20.html#SECTION00310000000000000000)\nDynamic Loading (node21.html#SECTION00400000000000000000)\n- Configuring and Building the Interpreter for Dynamic Loading (node22.html#SECTION00410000000000000000)\n- Shared Libraries (node23.html#SECTION00411000000000000000)\nSGI IRIX 4 Dynamic Loading (node24.html#SECTION00412000000000000000)\nGNU Dynamic Loading (node25.html#SECTION00413000000000000000)\nBuilding a Dynamically Loadable Module (node26.html#SECTION00420000000000000000)\n- Shared Libraries (node27.html#SECTION00421000000000000000)\nSGI IRIX 4 Dynamic Loading (node28.html#SECTION00422000000000000000)\nGNU Dynamic Loading (node29.html#SECTION00423000000000000000)\nAbout this document ... (node30.html#SECTION00500000000000000000)\n---\nnode1.html node1.html\n---\n---\nguido@cwi.nl", "python_version": "1.2", "length": 4322, "url": "https://docs.python.org/{python_version}/python-ext/ext.html"} {"title": "Footnotes", "text": "guido@cwi.nl", "python_version": "1.2", "length": 12, "url": "https://docs.python.org/{python_version}/python-ext/footnode.html"} {"title": "Contents", "text": "---\nnode2.html ext.html ext.html\n---\n## Contents\n- Extending Python with C or C++ code (node2.html#SECTION00200000000000000000)\n- Introduction (node3.html#SECTION00210000000000000000)\nA Simple Example (node4.html#SECTION00220000000000000000)\nIntermezzo: Errors and Exceptions (node5.html#SECTION00230000000000000000)\nBack to the Example (node6.html#SECTION00240000000000000000)\nThe Module's Method Table and Initialization Function (node7.html#SECTION00250000000000000000)\nCompilation and Linkage (node8.html#SECTION00260000000000000000)\nCalling Python Functions From C (node9.html#SECTION00270000000000000000)\nFormat Strings for PyArg_ParseTuple() (node10.html#SECTION00280000000000000000)\nThe Py_BuildValue() Function (node11.html#SECTION00290000000000000000)\nReference Counts (node12.html#SECTION002100000000000000000)\n- Introduction (node13.html#SECTION002101000000000000000)\nReference Counting in Python (node14.html#SECTION002102000000000000000)\nOwnership Rules (node15.html#SECTION002103000000000000000)\nThin Ice (node16.html#SECTION002104000000000000000)\nNULL Pointers (node17.html#SECTION002105000000000000000)\nWriting Extensions in C++ (node18.html#SECTION002110000000000000000)\nEmbedding Python in another application (node19.html#SECTION00300000000000000000)\n- Embedding Python in C++ (node20.html#SECTION00310000000000000000)\nDynamic Loading (node21.html#SECTION00400000000000000000)\n- Configuring and Building the Interpreter for Dynamic Loading (node22.html#SECTION00410000000000000000)\n- Shared Libraries (node23.html#SECTION00411000000000000000)\nSGI IRIX 4 Dynamic Loading (node24.html#SECTION00412000000000000000)\nGNU Dynamic Loading (node25.html#SECTION00413000000000000000)\nBuilding a Dynamically Loadable Module (node26.html#SECTION00420000000000000000)\n- Shared Libraries (node27.html#SECTION00421000000000000000)\nSGI IRIX 4 Dynamic Loading (node28.html#SECTION00422000000000000000)\nGNU Dynamic Loading (node29.html#SECTION00423000000000000000)\nAbout this document ... (node30.html#SECTION00500000000000000000)\n---\nguido@cwi.nl", "python_version": "1.2", "length": 2049, "url": "https://docs.python.org/{python_version}/python-ext/node1.html"} {"title": "Format Strings for PyArg_ParseTuple()", "text": "---\nnode11.html node2.html node9.html node1.html\n---\n# Format Strings for PyArg_ParseTuple()\nThe `PyArg_ParseTuple()` function is declared as follows:\n```text\nint PyArg_ParseTuple(PyObject *arg, char *format, ...);\n```\nThe arg argument must be a tuple object containing an argument\nlist passed from Python to a C function. The format argument\nmust be a format string, whose syntax is explained below. The\nremaining arguments must be addresses of variables whose type is\ndetermined by the format string. For the conversion to succeed, the\narg object must match the format and the format must be\nexhausted.\nNote that while `PyArg_ParseTuple()` checks that the Python\narguments have the required types, it cannot check the validity of the\naddresses of C variables passed to the call: if you make mistakes\nthere, your code will probably crash or at least overwrite random bits\nin memory. So be careful!\nA format string consists of zero or more ``format units''. A format\nunit describes one Python object; it is usually a single character or\na parenthesized sequence of format units. With a few exceptions, a\nformat unit that is not a parenthesized sequence normally corresponds\nto a single address argument to `PyArg_ParseTuple()`. In the\nfollowing description, the quoted form is the format unit; the entry\nin (round) parentheses is the Python object type that matches the\nformat unit; and the entry in [square] brackets is the type of the C\nvariable(s) whose address should be passed. (Use the `&'\noperator to pass a variable's address.)\nIt is possible to pass Python long integers where integers are\nrequested; however no proper range checking is done -- the most\nsignificant bits are silently truncated when the receiving field is\ntoo small to receive the value (actually, the semantics are inherited\nfrom downcasts in C --- your milage may vary).\nA few other characters have a meaning in a format string. These may\nnot occur inside nested parentheses. They are:\nSome example calls:\n```text\nint ok;\nint i, j;\nlong k, l;\nchar *s;\nint size;\n\nok = PyArg_ParseTuple(args, \"\"); /* No arguments */\n/* Python call: f() */\n\nok = PyArg_ParseTuple(args, \"s\", &s); /* A string */\n/* Possible Python call: f('whoops!') */\n\nok = PyArg_ParseTuple(args, \"lls\", &k, &l, &s); /* Two longs and a string */\n/* Possible Python call: f(1, 2, 'three') */\n\nok = PyArg_ParseTuple(args, \"(ii)s#\", &i, &j, &s, &size);\n/* A pair of ints and a string, whose size is also returned */\n/* Possible Python call: f(1, 2, 'three') */\n\n{\nchar *file;\nchar *mode = \"r\";\nint bufsize = 0;\nok = PyArg_ParseTuple(args, \"s|si\", &file, &mode, &bufsize);\n/* A string, and optionally another string and an integer */\n/* Possible Python calls:\nf('spam')\nf('spam', 'w')\nf('spam', 'wb', 100000) */\n}\n\n{\nint left, top, right, bottom, h, v;\nok = PyArg_ParseTuple(args, \"((ii)(ii))(ii)\",\n&left, &top, &right, &bottom, &h, &v);\n/* A rectangle and a point */\n/* Possible Python call:\nf(((0, 0), (400, 300)), (10, 10)) */\n}\n```\n---\nnode11.html node2.html node9.html node1.html\n---\n---\nguido@cwi.nl", "python_version": "1.2", "length": 3043, "url": "https://docs.python.org/{python_version}/python-ext/node10.html"} {"title": "The Py_BuildValue() Function", "text": "---\nnode12.html node2.html node10.html node1.html\n---\n# The Py_BuildValue() Function\nThis function is the counterpart to `PyArg_ParseTuple()`. It is\ndeclared as follows:\n```text\nPyObject *Py_BuildValue(char *format, ...);\n```\nIt recognizes a set of format units similar to the ones recognized by\n`PyArg_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), `BuildValue()` does\nnot always build a tuple. It builds a tuple only if its format string\ncontains two or more format units. If the format string is empty, it\nreturns `None`; if it contains exactly one format unit, it\nreturns whatever object is described by that format unit. To force it\nto return a tuple of size 0 or one, parenthesize the format string.\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.\nIf there is an error in the format string, the\n`PyExc_SystemError` exception is raised and `NULL` returned.\nExamples (to the left the call, to the right the resulting Python value):\n```text\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```\n---\nnode12.html node2.html node10.html node1.html\n---\n---\nguido@cwi.nl", "python_version": "1.2", "length": 2303, "url": "https://docs.python.org/{python_version}/python-ext/node11.html"} {"title": "Reference Counts", "text": "---\nnode13.html node2.html node11.html node1.html\n---\n# Reference Counts\n---\n- Introduction (node13.html#SECTION002101000000000000000)\nReference Counting in Python (node14.html#SECTION002102000000000000000)\nOwnership Rules (node15.html#SECTION002103000000000000000)\nThin Ice (node16.html#SECTION002104000000000000000)\nNULL Pointers (node17.html#SECTION002105000000000000000)\n---\nguido@cwi.nl", "python_version": "1.2", "length": 391, "url": "https://docs.python.org/{python_version}/python-ext/node12.html"} {"title": "Introduction", "text": "---\nnode14.html node12.html node12.html node1.html\n---\n## Introduction\nIn languages like C or C++, the programmer is responsible for\ndynamic allocation and deallocation of memory on the heap. In C, this\nis done using the functions `malloc()` and `free()`. In\nC++, the operators `new` and `delete` are used with\nessentially the same meaning; they are actually implemented using\n`malloc()` and `free()`, so we'll restrict the following\ndiscussion to the latter.\nEvery block of memory allocated with `malloc()` should eventually\nbe returned to the pool of available memory by exactly one call to\n`free()`. It is important to call `free()` at the right\ntime. If a block's address is forgotten but `free()` is not\ncalled for it, the memory it occupies cannot be reused until the\nprogram terminates. This is called a memory leak. On the other\nhand, if a program calls `free()` for a block and then continues\nto use the block, it creates a conflict with re-use of the block\nthrough another `malloc()` call. This is called using freed\nmemory has the same bad consequences as referencing uninitialized\ndata --- core dumps, wrong results, mysterious crashes.\nCommon causes of memory leaks are unusual paths through the code. For\ninstance, a function may allocate a block of memory, do some\ncalculation, and then free the block again. Now a change in the\nrequirements for the function may add a test to the calculation that\ndetects an error condition and can return prematurely from the\nfunction. It's easy to forget to free the allocated memory block when\ntaking this premature exit, especially when it is added later to the\ncode. Such leaks, once introduced, often go undetected for a long\ntime: the error exit is taken only in a small fraction of all calls,\nand most modern machines have plenty of virtual memory, so the leak\nonly becomes apparent in a long-running process that uses the leaking\nfunction frequently. Therefore, it's important to prevent leaks from\nhappening by having a coding convention or strategy that minimizes\nthis kind of errors.\nSince Python makes heavy use of malloc() and `free()`, it\nneeds a strategy to avoid memory leaks as well as the use of freed\nmemory. The chosen method is called `reference counting`. The\nprinciple is simple: every object contains a counter, which is\nincremented when a reference to the object is stored somewhere, and\nwhich is decremented when a reference to it is deleted. When the\ncounter reaches zero, the last reference to the object has been\ndeleted and the object is freed.\nAn alternative strategy is called automatic garbage collection.\n(Sometimes, reference counting is also referred to as a garbage\ncollection strategy, hence my use of ``automatic'' to distinguish the\ntwo.) The big advantage of automatic garbage collection is that the\nuser doesn't need to call free() explicitly. (Another claimed\nadvantage is an improvement in speed or memory usage --- this is no\nhard fact however.) The disadvantage is that for C, there is no\ntruly portable automatic garbage collector, while reference counting\ncan be implemented portably (as long as the functions `malloc()`\nand `free()` are available --- which the C Standard guarantees).\nMaybe some day a sufficiently portable automatic garbage collector\nwill be available for C. Until then, we'll have to live with\nreference counts.\n---\nnode14.html node12.html node12.html node1.html\n---\n---\nguido@cwi.nl", "python_version": "1.2", "length": 3401, "url": "https://docs.python.org/{python_version}/python-ext/node13.html"} {"title": "Reference Counting in Python", "text": "---\nnode15.html node12.html node13.html node1.html\n---\n## Reference Counting in Python\nThere are two macros, `Py_INCREF(x)` and `Py_DECREF(x)`,\nwhich handle the incrementing and decrementing of the reference count.\n`Py_DECREF()` also frees the object when the count reaches zero.\nFor flexibility, it doesn't call `free()` directly --- rather, it\nmakes a call through a function pointer in the object's type\nobject. For this purpose (and others), every object also contains a\npointer to its type object.\nThe big question now remains: when to use Py_INCREF(x) and\n`Py_DECREF(x)`? Let's first introduce some terms. Nobody\n``owns'' an object; however, you can `own a reference` to an\nobject. An object's reference count is now defined as the number of\nowned references to it. The owner of a reference is responsible for\ncalling Py_DECREF() when the reference is no longer needed.\nOwnership of a reference can be transferred. There are three ways to\ndispose of an owned reference: pass it on, store it, or call\n`Py_DECREF()`. Forgetting to dispose of an owned reference creates\na memory leak.\nIt is also possible to `borrow`footnode.html#371 a reference to an object. The borrower\nof a reference should not call Py_DECREF(). The borrower must\nnot hold on to the object longer than the owner from which it was\nborrowed. Using a borrowed reference after the owner has disposed of\nit risks using freed memory and should be avoided\ncompletely.footnode.html#538\nThe advantage of borrowing over owning a reference is that you don't\nneed to take care of disposing of the reference on all possible paths\nthrough the code --- in other words, with a borrowed reference you\ndon't run the risk of leaking when a premature exit is taken. The\ndisadvantage of borrowing over leaking is that there are some subtle\nsituations where in seemingly correct code a borrowed reference can be\nused after the owner from which it was borrowed has in fact disposed\nof it.\nA borrowed reference can be changed into an owned reference by calling\n`Py_INCREF()`. This does not affect the status of the owner from\nwhich the reference was borrowed --- it creates a new owned reference,\nand gives full owner responsibilities (i.e., the new owner must\ndispose of the reference properly, as well as the previous owner).\n---\nnode15.html node12.html node13.html node1.html\n---\n---\nguido@cwi.nl", "python_version": "1.2", "length": 2349, "url": "https://docs.python.org/{python_version}/python-ext/node14.html"} {"title": "Ownership Rules", "text": "---\nnode16.html node12.html node14.html node1.html\n---\n## Ownership Rules\nWhenever an object reference is passed into or out of a function, it\nis part of the function's interface specification whether ownership is\ntransferred with the reference or not.\nMost functions that return a reference to an object pass on ownership\nwith the reference. In particular, all functions whose function it is\nto create a new object, e.g. `PyInt_FromLong()` and\n`Py_BuildValue()`, pass ownership to the receiver. Even if in\nfact, in some cases, you don't receive a reference to a brand new\nobject, you still receive ownership of the reference. For instance,\n`PyInt_FromLong()` maintains a cache of popular values and can\nreturn a reference to a cached item.\nMany functions that extract objects from other objects also transfer\nownership with the reference, for instance\n`PyObject_GetAttrString()`. The picture is less clear, here,\nhowever, since a few common routines are exceptions:\n`PyTuple_GetItem()`, `PyList_GetItem()` and\n`PyDict_GetItem()` (and `PyDict_GetItemString()`) all return\nreferences that you borrow from the tuple, list or dictionary.\nThe function `PyImport_AddModule()` also returns a borrowed\nreference, even though it may actually create the object it returns:\nthis is possible because an owned reference to the object is stored in\n`sys.modules`.\nWhen you pass an object reference into another function, in general,\nthe function borrows the reference from you --- if it needs to store\nit, it will use `Py_INCREF()` to become an independent owner.\nThere are exactly two important exceptions to this rule:\n`PyTuple_SetItem()` and `PyList_SetItem()`. These functions\ntake over ownership of the item passed to them --- even if they fail!\n(Note that `PyDict_SetItem()` and friends don't take over\nownership --- they are ``normal''.)\nWhen a C function is called from Python, it borrows references to its\narguments from the caller. The caller owns a reference to the object,\nso the borrowed reference's lifetime is guaranteed until the function\nreturns. Only when such a borrowed reference must be stored or passed\non, it must be turned into an owned reference by calling\n`Py_INCREF()`.\nThe object reference returned from a C function that is called from\nPython must be an owned reference --- ownership is tranferred from the\nfunction to its caller.\n---\nnode16.html node12.html node14.html node1.html\n---\n---\nguido@cwi.nl", "python_version": "1.2", "length": 2417, "url": "https://docs.python.org/{python_version}/python-ext/node15.html"} {"title": "Thin Ice", "text": "---\nnode17.html node12.html node15.html node1.html\n---\n## Thin Ice\nThere are a few situations where seemingly harmless use of a borrowed\nreference can lead to problems. These all have to do with implicit\ninvocations of the interpreter, which can cause the owner of a\nreference to dispose of it.\nThe first and most important case to know about is using\n`Py_DECREF()` on an unrelated object while borrowing a reference\nto a list item. For instance:\n```text\nbug(PyObject *list) {\nPyObject *item = PyList_GetItem(list, 0);\nPyList_SetItem(list, 1, PyInt_FromLong(0L));\nPyObject_Print(item, stdout, 0); /* BUG! */\n}\n```\nThis function first borrows a reference to `list[0]`, then\nreplaces `list[1]` with the value `0`, and finally prints\nthe borrowed reference. Looks harmless, right? But it's not!\nLet's follow the control flow into `PyList_SetItem()`. The list\nowns references to all its items, so when item 1 is replaced, it has\nto dispose of the original item 1. Now let's suppose the original\nitem 1 was an instance of a user-defined class, and let's further\nsuppose that the class defined a `__del__()` method. If this\nclass instance has a reference count of 1, disposing of it will call\nits `__del__()` method.\nSince it is written in Python, the `__del__()` method can execute\narbitrary Python code. Could it perhaps do something to invalidate\nthe reference to `item` in `bug()`? You bet! Assuming that\nthe list passed into `bug()` is accessible to the\n`__del__()` method, it could execute a statement to the effect of\n`del list[0]`, and assuming this was the last reference to that\nobject, it would free the memory associated with it, thereby\ninvalidating `item`.\nThe solution, once you know the source of the problem, is easy:\ntemporarily increment the reference count. The correct version of the\nfunction reads:\n```text\nno_bug(PyObject *list) {\nPyObject *item = PyList_GetItem(list, 0);\nPy_INCREF(item);\nPyList_SetItem(list, 1, PyInt_FromLong(0L));\nPyObject_Print(item, stdout, 0);\nPy_DECREF(item);\n}\n```\nThis is a true story. An older version of Python contained variants\nof this bug and someone spent a considerable amount of time in a C\ndebugger to figure out why his `__del__()` methods would fail...\nThe second case of problems with a borrowed reference is a variant\ninvolving threads. Normally, multiple threads in the Python\ninterpreter can't get in each other's way, because there is a global\nlock protecting Python's entire object space. However, it is possible\nto temporarily release this lock using the macro\n`Py_BEGIN_ALLOW_THREADS`, and to re-acquire it using\n`Py_END_ALLOW_THREADS`. This is common around blocking I/O\ncalls, to let other threads use the CPU while waiting for the I/O to\ncomplete. Obviously, the following function has the same problem as\nthe previous one:\n```text\nbug(PyObject *list) {\nPyObject *item = PyList_GetItem(list, 0);\nPy_BEGIN_ALLOW_THREADS\n...some blocking I/O call...\nPy_END_ALLOW_THREADS\nPyObject_Print(item, stdout, 0); /* BUG! */\n}\n```\n---\nnode17.html node12.html node15.html node1.html\n---\n---\nguido@cwi.nl", "python_version": "1.2", "length": 3056, "url": "https://docs.python.org/{python_version}/python-ext/node16.html"} {"title": "NULL Pointers", "text": "---\nnode18.html node12.html node16.html node1.html\n---\n## NULL Pointers\nIn general, functions that take object references as arguments don't\nexpect you to pass them `NULL` pointers, and will dump core (or\ncause later core dumps) if you do so. Functions that return object\nreferences generally return `NULL` only to indicate that an\nexception occurred. The reason for not testing for `NULL`\narguments is that functions often pass the objects they receive on to\nother function --- if each function were to test for `NULL`,\nthere would be a lot of redundant tests and the code would run slower.\nIt is better to test for `NULL` only at the ``source'', i.e.\\\nwhen a pointer that may be `NULL` is received, e.g. from\n`malloc()` or from a function that may raise an exception.\nThe macros `Py_INCREF()` and `Py_DECREF()`\ndon't check for `NULL` pointers --- however, their variants\n`Py_XINCREF()` and `Py_XDECREF()` do.\nThe macros for checking for a particular object type\n(`Py type _Check()`) don't check for `NULL` pointers ---\nagain, there is much code that calls several of these in a row to test\nan object against various different expected types, and this would\ngenerate redundant tests. There are no variants with `NULL`\nchecking.\nThe C function calling mechanism guarantees that the argument list\npassed to C functions (`args` in the examples) is never\n`NULL` --- in fact it guarantees that it is always a tuple.\nfootnode.html#427\nIt is a severe error to ever let a `NULL` pointer ``escape'' to\nthe Python user.\n---\nguido@cwi.nl", "python_version": "1.2", "length": 1527, "url": "https://docs.python.org/{python_version}/python-ext/node17.html"} {"title": "Writing Extensions in C++", "text": "---\nnode19.html node2.html node17.html node1.html\n---\n# Writing Extensions in C++\nIt is possible to write extension modules in C++. Some restrictions\napply: since the main program (the Python interpreter) is compiled and\nlinked by the C compiler, global or static objects with constructors\ncannot be used. All functions that will be called directly or\nindirectly (i.e. via function pointers) by the Python interpreter will\nhave to be declared using `extern \"C\"`; this applies to all\n``methods'' as well as to the module's initialization function.\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).\n---\nguido@cwi.nl", "python_version": "1.2", "length": 755, "url": "https://docs.python.org/{python_version}/python-ext/node18.html"} {"title": "Embedding Python in another application", "text": "---\nnode20.html ext.html node18.html node1.html\n---\n# Embedding Python in another application\nEmbedding Python is similar to extending it, but not quite. The\ndifference is that when you extend Python, the main program of the\napplication is still the Python interpreter, while if you embed\nPython, the main program may have nothing to do with Python ---\ninstead, some parts of the application occasionally call the Python\ninterpreter to run some Python code.\nSo if you are embedding Python, you are providing your own main\nprogram. One of the things this main program has to do is initialize\nthe Python interpreter. At the very least, you have to call the\nfunction `Py_Initialize()`. There are optional calls to pass command\nline arguments to Python. Then later you can call the interpreter\nfrom any part of the application.\nThere are several different ways to call the interpreter: you can pass\na string containing Python statements to `PyRun_SimpleString()`,\nor you can pass a stdio file pointer and a file name (for\nidentification in error messages only) to `PyRun_SimpleFile()`. You\ncan also call the lower-level operations described in the previous\nchapters to construct and use Python objects.\nA simple demo of embedding Python can be found in the directory\n``Demo/embed`'.\n---\n- Embedding Python in C++ (node20.html#SECTION00310000000000000000)\n---\nguido@cwi.nl", "python_version": "1.2", "length": 1367, "url": "https://docs.python.org/{python_version}/python-ext/node19.html"} {"title": "Extending Python with C or C++ code", "text": "---\nnode3.html ext.html node1.html node1.html\n---\n# Extending Python with C or C++ code\n---\n- Introduction (node3.html#SECTION00210000000000000000)\nA Simple Example (node4.html#SECTION00220000000000000000)\nIntermezzo: Errors and Exceptions (node5.html#SECTION00230000000000000000)\nBack to the Example (node6.html#SECTION00240000000000000000)\nThe Module's Method Table and Initialization Function (node7.html#SECTION00250000000000000000)\nCompilation and Linkage (node8.html#SECTION00260000000000000000)\nCalling Python Functions From C (node9.html#SECTION00270000000000000000)\nFormat Strings for PyArg_ParseTuple() (node10.html#SECTION00280000000000000000)\nThe Py_BuildValue() Function (node11.html#SECTION00290000000000000000)\nReference Counts (node12.html#SECTION002100000000000000000)\n- Introduction (node13.html#SECTION002101000000000000000)\nReference Counting in Python (node14.html#SECTION002102000000000000000)\nOwnership Rules (node15.html#SECTION002103000000000000000)\nThin Ice (node16.html#SECTION002104000000000000000)\nNULL Pointers (node17.html#SECTION002105000000000000000)\nWriting Extensions in C++ (node18.html#SECTION002110000000000000000)\n---\nguido@cwi.nl", "python_version": "1.2", "length": 1169, "url": "https://docs.python.org/{python_version}/python-ext/node2.html"} {"title": "Embedding Python in C++", "text": "---\nnode21.html node19.html node19.html node1.html\n---\n# Embedding Python in C++\nIt is also possible to embed Python in a C++ program; precisely how this\nis done will depend on the details of the C++ system used; in general you\nwill need to write the main program in C++, and use the C++ compiler\nto compile and link your program. There is no need to recompile Python\nitself using C++.\n---\nguido@cwi.nl", "python_version": "1.2", "length": 402, "url": "https://docs.python.org/{python_version}/python-ext/node20.html"} {"title": "Dynamic Loading", "text": "---\nnode22.html ext.html node20.html node1.html\n---\n# Dynamic Loading\nOn most modern systems it is possible to configure Python to support\ndynamic loading of extension modules implemented in C. When shared\nlibraries are used dynamic loading is configured automatically;\notherwise you have to select it as a build option (see below). Once\nconfigured, dynamic loading is trivial to use: when a Python program\nexecutes `import spam`, the search for modules tries to find a\nfile ``spammodule.o`' (``spammodule.so`' when using shared\nlibraries) in the module search path, and if one is found, it is\nloaded into the executing binary and executed. Once loaded, the\nmodule acts just like a built-in extension module.\nThe advantages of dynamic loading are twofold: the ``core'' Python\nbinary gets smaller, and users can extend Python with their own\nmodules implemented in C without having to build and maintain their\nown copy of the Python interpreter. There are also disadvantages:\ndynamic loading isn't available on all systems (this just means that\non some systems you have to use static loading), and dynamically\nloading a module that was compiled for a different version of Python\n(e.g. with a different representation of objects) may dump core.\n---\n- Configuring and Building the Interpreter for Dynamic Loading (node22.html#SECTION00410000000000000000)\n- Shared Libraries (node23.html#SECTION00411000000000000000)\nSGI IRIX 4 Dynamic Loading (node24.html#SECTION00412000000000000000)\nGNU Dynamic Loading (node25.html#SECTION00413000000000000000)\nBuilding a Dynamically Loadable Module (node26.html#SECTION00420000000000000000)\n- Shared Libraries (node27.html#SECTION00421000000000000000)\nSGI IRIX 4 Dynamic Loading (node28.html#SECTION00422000000000000000)\nGNU Dynamic Loading (node29.html#SECTION00423000000000000000)\n---\nguido@cwi.nl", "python_version": "1.2", "length": 1832, "url": "https://docs.python.org/{python_version}/python-ext/node21.html"} {"title": "Configuring and Building the Interpreter for Dynamic Loading", "text": "---\nnode23.html node21.html node21.html node1.html\n---\n# Configuring and Building the Interpreter for Dynamic Loading\nThere are three styles of dynamic loading: one using shared libraries,\none using SGI IRIX 4 dynamic loading, and one using GNU dynamic\nloading.\n---\n- Shared Libraries (node23.html#SECTION00411000000000000000)\nSGI IRIX 4 Dynamic Loading (node24.html#SECTION00412000000000000000)\nGNU Dynamic Loading (node25.html#SECTION00413000000000000000)\n---\nguido@cwi.nl", "python_version": "1.2", "length": 474, "url": "https://docs.python.org/{python_version}/python-ext/node22.html"} {"title": "Shared Libraries", "text": "---\nnode24.html node22.html node22.html node1.html\n---\n## Shared Libraries\nThe following systems support dynamic loading using shared libraries:\nSunOS 4; Solaris 2; SGI IRIX 5 (but not SGI IRIX 4!); and probably all\nsystems derived from SVR4, or at least those SVR4 derivatives that\nsupport shared libraries (are there any that don't?).\nYou don't need to do anything to configure dynamic loading on these\nsystems --- the ``configure`' detects the presence of the\n```' header file and automatically configures dynamic\nloading.\n---\nguido@cwi.nl", "python_version": "1.2", "length": 551, "url": "https://docs.python.org/{python_version}/python-ext/node23.html"} {"title": "SGI IRIX 4 Dynamic Loading", "text": "---\nnode25.html node22.html node23.html node1.html\n---\n## SGI IRIX 4 Dynamic Loading\nOnly SGI IRIX 4 supports dynamic loading of modules using SGI dynamic\nloading. (SGI IRIX 5 might also support it but it is inferior to\nusing shared libraries so there is no reason to; a small test didn't\nwork right away so I gave up trying to support it.)\nBefore you build Python, you first need to fetch and build the `dl`\npackage written by Jack Jansen. This is available by anonymous ftp\nfrom host ``ftp.cwi.nl`', directory ``pub/dynload`', file\n``dl-1.6.tar.Z`'. (The version number may change.) Follow the\ninstructions in the package's ``README`' file to build it.\nOnce you have built `dl`, you can configure Python to use it. To\nthis end, you run the ``configure`' script with the option\n`--with-dl= directory` where directory is the absolute\npathname of the `dl` directory.\nNow build and install Python as you normally would (see the\n``README`' file in the toplevel Python directory.)\n---\nguido@cwi.nl", "python_version": "1.2", "length": 993, "url": "https://docs.python.org/{python_version}/python-ext/node24.html"} {"title": "GNU Dynamic Loading", "text": "---\nnode26.html node22.html node24.html node1.html\n---\n## GNU Dynamic Loading\nGNU dynamic loading supports (according to its ``README`' file) the\nfollowing hardware and software combinations: VAX (Ultrix), Sun 3\n(SunOS 3.4 and 4.0), Sparc (SunOS 4.0), Sequent Symmetry (Dynix), and\nAtari ST. There is no reason to use it on a Sparc; I haven't seen a\nSun 3 for years so I don't know if these have shared libraries or not.\nYou need to fetch and build two packages. One is GNU DLD 3.2.3,\navailable by anonymous ftp from host ``ftp.cwi.nl`', directory\n``pub/dynload`', file ``dld-3.2.3.tar.Z`'. (As far as I know,\nno further development on GNU DLD is being done.) The other is an\nemulation of Jack Jansen's `dl` package that I wrote on top of\nGNU DLD 3.2.3. This is available from the same host and directory,\nfile dl-dld-1.1.tar.Z. (The version number may change --- but I doubt\nit will.) Follow the instructions in each package's ``README`'\nfile to configure build them.\nNow configure Python. Run the ``configure`' script with the option\n`--with-dl-dld= dl-directory , dld-directory` where\ndl-directory is the absolute pathname of the directory where you\nhave built the ``dl-dld`' package, and dld-directory is that\nof the GNU DLD package. The Python interpreter you build hereafter\nwill support GNU dynamic loading.\n---\nguido@cwi.nl", "python_version": "1.2", "length": 1331, "url": "https://docs.python.org/{python_version}/python-ext/node25.html"} {"title": "Building a Dynamically Loadable Module", "text": "---\nnode27.html node21.html node25.html node1.html\n---\n# Building a Dynamically Loadable Module\nSince there are three styles of dynamic loading, there are also three\ngroups of instructions for building a dynamically loadable module.\nInstructions common for all three styles are given first. Assuming\nyour module is called `spam`, the source filename must be\n``spammodule.c`', so the object name is ``spammodule.o`'. The\nmodule must be written as a normal Python extension module (as\ndescribed earlier).\nNote that in all cases you will have to create your own Makefile that\ncompiles your module file(s). This Makefile will have to pass two\n`-I' arguments to the C compiler which will make it find the\nPython header files. If the Make variable PYTHONTOP points to\nthe toplevel Python directory, your CFLAGS Make variable should\ncontain the options `-I$(PYTHONTOP) -I$(PYTHONTOP)/Include'.\n(Most header files are in the ``Include`' subdirectory, but the\n``config.h`' header lives in the toplevel directory.) You must\nalso add `-DHAVE_CONFIG_H' to the definition of CFLAGS to\ndirect the Python headers to include ``config.h`'.\n---\n- Shared Libraries (node27.html#SECTION00421000000000000000)\nSGI IRIX 4 Dynamic Loading (node28.html#SECTION00422000000000000000)\nGNU Dynamic Loading (node29.html#SECTION00423000000000000000)\n---\nguido@cwi.nl", "python_version": "1.2", "length": 1335, "url": "https://docs.python.org/{python_version}/python-ext/node26.html"} {"title": "Shared Libraries", "text": "---\nnode28.html node26.html node26.html node1.html\n---\n## Shared Libraries\nYou must link the `.o' file to produce a shared library. This is\ndone using a special invocation of the Unix loader/linker,\nld(1). Unfortunately the invocation differs slightly per system.\nOn SunOS 4, use\n```text\nld spammodule.o -o spammodule.so\n```\nOn Solaris 2, use\n```text\nld -G spammodule.o -o spammodule.so\n```\nOn SGI IRIX 5, use\n```text\nld -shared spammodule.o -o spammodule.so\n```\nOn other systems, consult the manual page for `ld`(1) to find what\nflags, if any, must be used.\nIf your extension module uses system libraries that haven't already\nbeen linked with Python (e.g. a windowing system), these must be\npassed to the `ld` command as `-l' options after the\n`.o' file.\nThe resulting file ``spammodule.so`' must be copied into a directory\nalong the Python module search path.\n---\nguido@cwi.nl", "python_version": "1.2", "length": 878, "url": "https://docs.python.org/{python_version}/python-ext/node27.html"} {"title": "SGI IRIX 4 Dynamic Loading", "text": "---\nnode29.html node26.html node27.html node1.html\n---\n## SGI IRIX 4 Dynamic Loading\nIMPORTANT: You must compile your extension module with the\nadditional C flag `-G0' (or `-G 0'). This instruct the\nassembler to generate position-independent code.\nYou don't need to link the resulting ``spammodule.o`' file; just\ncopy it into a directory along the Python module search path.\nThe first time your extension is loaded, it takes some extra time and\na few messages may be printed. This creates a file\n``spammodule.ld`' which is an image that can be loaded quickly into\nthe Python interpreter process. When a new Python interpreter is\ninstalled, the `dl` package detects this and rebuilds\n``spammodule.ld`'. The file ``spammodule.ld`' is placed in the\ndirectory where ``spammodule.o`' was found, unless this directory is\nunwritable; in that case it is placed in a temporary\ndirectory.footnode.html#544\nIf your extension modules uses additional system libraries, you must\ncreate a file ``spammodule.libs`' in the same directory as the\n``spammodule.o`'. This file should contain one or more lines with\nwhitespace-separated options that will be passed to the linker ---\nnormally only `-l' options or absolute pathnames of libraries\n(`.a' files) should be used.\n---\nguido@cwi.nl", "python_version": "1.2", "length": 1268, "url": "https://docs.python.org/{python_version}/python-ext/node28.html"} {"title": "GNU Dynamic Loading", "text": "---\nnode30.html node26.html node28.html node1.html\n---\n## GNU Dynamic Loading\nJust copy ``spammodule.o`' into a directory along the Python module\nsearch path.\nIf your extension modules uses additional system libraries, you must\ncreate a file ``spammodule.libs`' in the same directory as the\n``spammodule.o`'. This file should contain one or more lines with\nwhitespace-separated absolute pathnames of libraries (`.a'\nfiles). No `-l' options can be used.\n---\nguido@cwi.nl", "python_version": "1.2", "length": 469, "url": "https://docs.python.org/{python_version}/python-ext/node29.html"} {"title": "Introduction", "text": "---\nnode4.html node2.html node2.html node1.html\n---\n# Introduction\nIt is quite easy to add new built-in modules to Python, if you know\nhow to program in C. Such extension modules can do two things\nthat can't be done directly in Python: they can implement new built-in\nobject types, and they can call C library functions and system calls.\nTo support extensions, the Python API (Application Programmers\nInterface) defines a set of functions, macros and variables that\nprovide access to most aspects of the Python run-time system. The\nPython API is incorporated in a C source file by including the header\n`\"Python.h\"`.\nThe compilation of an extension module depends on its intended use as\nwell as on your system setup; details are given in a later section.\n---\nguido@cwi.nl", "python_version": "1.2", "length": 770, "url": "https://docs.python.org/{python_version}/python-ext/node3.html"} {"title": "About this document ...", "text": "---\next.html node29.html node1.html\n---\n# About this document ...\nExtending and Embedding the Python Interpreter\nThis document was generated using the LaTeX2HTML (http://cbl.leeds.ac.uk/nikos/tex2html/doc/latex2html/latex2html.html) translator Version 95.1 (Fri Jan 20 1995) Copyright © 1993, 1994, Nikos Drakos (http://cbl.leeds.ac.uk/nikos/personal.html), Computer Based Learning Unit, University of Leeds.\nThe command line arguments were:\nlatex2html -address guido@cwi.nl -dont_include myformat ext.tex.\nThe translation was initiated by Guido van Rossum on Tue Apr 11 00:22:00 MDT 1995\n---\nguido@cwi.nl", "python_version": "1.2", "length": 605, "url": "https://docs.python.org/{python_version}/python-ext/node30.html"} {"title": "A Simple Example", "text": "---\nnode5.html node2.html node3.html node1.html\n---\n# A Simple Example\nLet's create an extension module called `spam' (the favorite food\nof Monty Python fans...) and let's say we want to create a Python\ninterface to the C library function `system()`.footnode.html#522\nThis function takes a null-terminated character string as argument and\nreturns an integer. We want this function to be callable from Python\nas follows:\n```text\n>>> import spam\n>>> status = spam.system(\"ls -l\")\n```\nBegin by creating a file `spammodule.c'. (In general, if a\nmodule is called `spam', the C file containing its implementation\nis called ``spammodule.c`'; if the module name is very long, like\n`spammify', the module name can be just ``spammify.c`'.)\nThe first line of our file can be:\n```text\n#include \"Python.h\"\n```\nwhich pulls in the Python API (you can add a comment describing the\npurpose of the module and a copyright notice if you like).\nAll user-visible symbols defined by `\"Python.h\"` have a prefix of\n`Py' or `PY', except those defined in standard header files.\nFor convenience, and since they are used extensively by the Python\ninterpreter, `\"Python.h\"` includes a few standard header files:\n``, ``, ``, and\n``. If the latter header file does not exist on your\nsystem, it declares the functions `malloc()`, `free()` and\n`realloc()` directly.\nThe next thing we add to our module file is the C function that will\nbe called when the Python expression `spam.system(string)'\nis evaluated (we'll see shortly how it ends up being called):\n```text\nstatic PyObject *\nspam_system(self, args)\nPyObject *self;\nPyObject *args;\n{\nchar *command;\nint sts;\nif (!PyArg_ParseTuple(args, \"s\", &command))\nreturn NULL;\nsts = system(command);\nreturn Py_BuildValue(\"i\", sts);\n}\n```\nThere is a straightforward translation from the argument list in\nPython (e.g. the single expression `\"ls -l\"`) to the arguments\npassed to the C function. The C function always has two arguments,\nconventionally named self and args.\nThe self argument is only used when the C function implements a\nbuiltin method. This will be discussed later. In the example,\nself will always be a `NULL` pointer, since we are defining\na function, not a method. (This is done so that the interpreter\ndoesn't have to understand two different types of C functions.)\nThe args argument will be a pointer to a Python tuple object\ncontaining the arguments. Each item of the tuple corresponds to an\nargument in the call's argument list. The arguments are Python\nobjects -- in order to do anything with them in our C function we have\nto convert them to C values. The function `PyArg_ParseTuple()`\nin the Python API checks the argument types and converts them to C\nvalues. It uses a template string to determine the required types of\nthe arguments as well as the types of the C variables into which to\nstore the converted values. More about this later.\n`PyArg_ParseTuple()` returns true (nonzero) if all arguments have\nthe right type and its components have been stored in the variables\nwhose addresses are passed. It returns false (zero) if an invalid\nargument list was passed. In the latter case it also raises an\nappropriate exception by so the calling function can return\n`NULL` immediately (as we saw in the example).\n---\nnode5.html node2.html node3.html node1.html\n---\n---\nguido@cwi.nl", "python_version": "1.2", "length": 3349, "url": "https://docs.python.org/{python_version}/python-ext/node4.html"} {"title": "Intermezzo: Errors and Exceptions", "text": "---\nnode6.html node2.html node4.html node1.html\n---\n# Intermezzo: Errors and Exceptions\nAn important convention throughout the Python interpreter is the\nfollowing: when a function fails, it should set an exception condition\nand return an error value (usually a `NULL` pointer). Exceptions\nare stored in a static global variable inside the interpreter; if this\nvariable is `NULL` no exception has occurred. A second global\nvariable stores the ``associated value'' of the exception (the second\nargument to `raise`). A third variable contains the stack\ntraceback in case the error originated in Python code. These three\nvariables are the C equivalents of the Python variables\n`sys.exc_type`, `sys.exc_value` and `sys.exc_traceback`\n(see the section on module `sys` in the Library Reference\nManual). It is important to know about them to understand how errors\nare passed around.\nThe Python API defines a number of functions to set various types of\nexceptions.\nThe most common one is `PyErr_SetString()`. Its arguments are an\nexception object and a C string. The exception object is usually a\npredefined object like `PyExc_ZeroDivisionError`. The C string\nindicates the cause of the error and is converted to a Python string\nobject and stored as the ``associated value'' of the exception.\nAnother useful function is `PyErr_SetFromErrno()`, which only\ntakes an exception argument and constructs the associated value by\ninspection of the (Unix) global variable `errno`. The most\ngeneral function is `PyErr_SetObject()`, which takes two object\narguments, the exception and its associated value. You don't need to\n`Py_INCREF()` the objects passed to any of these functions.\nYou can test non-destructively whether an exception has been set with\n`PyErr_Occurred()`. This returns the current exception object,\nor `NULL` if no exception has occurred. You normally don't need\nto call `PyErr_Occurred()` to see whether an error occurred in a\nfunction call, since you should be able to tell from the return value.\nWhen a function f that calls another function varg detects\nthat the latter fails, f should itself return an error value\n(e.g. `NULL` or `-1`). It should not call one of the\n`PyErr_*()` functions --- one has already been called by g.\nf's caller is then supposed to also return an error indication\nto its caller, again without calling `PyErr_*()`,\nand so on --- the most detailed cause of the error was already\nreported by the function that first detected it. Once the error\nreaches the Python interpreter's main loop, this aborts the currently\nexecuting Python code and tries to find an exception handler specified\nby the Python programmer.\n(There are situations where a module can actually give a more detailed\nerror message by calling another `PyErr_*()` function, and in\nsuch cases it is fine to do so. As a general rule, however, this is\nnot necessary, and can cause information about the cause of the error\nto be lost: most operations can fail for a variety of reasons.)\nTo ignore an exception set by a function call that failed, the exception\ncondition must be cleared explicitly by calling `PyErr_Clear()`.\nThe only time C code should call `PyErr_Clear()` is if it doesn't\nwant to pass the error on to the interpreter but wants to handle it\ncompletely by itself (e.g. by trying something else or pretending\nnothing happened).\nNote that a failing `malloc()` call must be turned into an\nexception --- the direct caller of `malloc()` (or\n`realloc()`) must call `PyErr_NoMemory()` and return a\nfailure indicator itself. All the object-creating functions\n(`PyInt_FromLong()` etc.) already do this, so only if you call\n`malloc()` directly this note is of importance.\nAlso note that, with the important exception of\n`PyArg_ParseTuple()` and friends, functions that return an\ninteger status usually return a positive value or zero for success and\n`-1` for failure, like Unix system calls.\nFinally, be careful to clean up garbage (by making `Py_XDECREF()`\nor `Py_DECREF()` calls for objects you have already created) when\nyou return an error indicator!\nThe choice of which exception to raise is entirely yours. There are\npredeclared C objects corresponding to all built-in Python exceptions,\ne.g. `PyExc_ZeroDevisionError` which you can use directly. Of\ncourse, you should choose exceptions wisely --- don't use\n`PyExc_TypeError` to mean that a file couldn't be opened (that\nshould probably be `PyExc_IOError`). If something's wrong with\nthe argument list, the `PyArg_ParseTuple()` function usually\nraises `PyExc_TypeError`. If you have an argument whose value\nwhich must be in a particular range or must satisfy other conditions,\n`PyExc_ValueError` is appropriate.\nYou can also define a new exception that is unique to your module.\nFor this, you usually declare a static object variable at the\nbeginning of your file, e.g.\n```text\nstatic PyObject *SpamError;\n```\nand initialize it in your module's initialization function\n(`initspam()`) with a string object, e.g. (leaving out the error\nchecking for now):\n```text\nvoid\ninitspam()\n{\nPyObject *m, *d;\nm = Py_InitModule(\"spam\", SpamMethods);\nd = PyModule_GetDict(m);\nSpamError = PyString_FromString(\"spam.error\");\nPyDict_SetItemString(d, \"error\", SpamError);\n}\n```\nNote that the Python name for the exception object is\n`spam.error`. It is conventional for module and exception names\nto be spelled in lower case. It is also conventional that the\nvalue of the exception object is the same as its name, e.g.\\\nthe string `\"spam.error\"`.\n---\nnode6.html node2.html node4.html node1.html\n---\n---\nguido@cwi.nl", "python_version": "1.2", "length": 5544, "url": "https://docs.python.org/{python_version}/python-ext/node5.html"} {"title": "Back to the Example", "text": "---\nnode7.html node2.html node5.html node1.html\n---\n# Back to the Example\nGoing back to our example function, you should now be able to\nunderstand this statement:\n```text\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\n`command`. This is a pointer assignment and you are not supposed\nto modify the string to which it points (so in Standard C, the variable\n`command` should properly be declared as const char\n*command).\nThe next statement is a call to the ' function `system()`,\npassing it the string we just got from `PyArg_ParseTuple()`:\n```text\nsts = system(command);\n```\nOur `spam.system()` function must return the value of `sys`\nas a Python object. This is done using the function\n`Py_BuildValue()`, which is something like the inverse of\n`PyArg_ParseTuple()`: it takes a format string and an arbitrary\nnumber of C values, and returns a new Python object. More info on\n`Py_BuildValue()` is given later.\n```text\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\nPy_INCREF(Py_None);\nreturn Py_None;\n```\n`Py_None` is the C name for the special Python object\n`None`. It is a genuine Python object (not a `NULL`\npointer, which means ``error'' in most contexts, as we have seen).\n---\nguido@cwi.nl", "python_version": "1.2", "length": 1739, "url": "https://docs.python.org/{python_version}/python-ext/node6.html"} {"title": "The Module's Method Table and Initialization Function", "text": "---\nnode8.html node2.html node6.html node1.html\n---\n# The Module's Method Table and Initialization Function\nI promised to show how `spam_system()` is called from Python\nprograms. First, we need to list its name and address in a ``method\ntable'':\n```text\nstatic PyMethodDef SpamMethods[] = {\n...\n{\"system\", spam_system, 1},\n...\n{NULL, NULL} /* Sentinel */\n};\n```\nNote the third entry (`1'). This is a flag telling the\ninterpreter the calling convention to be used for the C function. It\nshould normally always be `1'; a value of `0' means that an\nobsolete variant of `PyArg_ParseTuple()` is used.\nThe method table must be passed to the interpreter in the module's\ninitialization function (which should be the only non-`static`\nitem defined in the module file):\n```text\nvoid\ninitspam()\n{\n(void) Py_InitModule(\"spam\", SpamMethods);\n}\n```\nWhen the Python program imports module `spam` for the first time,\n`initspam()` is called. It calls `Py_InitModule()`, which\ncreates a ``module object'' (which is inserted in the dictionary\n`sys.modules` under the key `\"spam\"`), and inserts built-in\nfunction objects into the newly created module based upon the table\n(an array of `PyMethodDef` structures) that was passed as its\nsecond argument. `Py_InitModule()` returns a pointer to the\nmodule object that it creates (which is unused here). It aborts with\na fatal error if the module could not be initialized satisfactorily,\nso the caller doesn't need to check for errors.\n---\nguido@cwi.nl", "python_version": "1.2", "length": 1476, "url": "https://docs.python.org/{python_version}/python-ext/node7.html"} {"title": "Compilation and Linkage", "text": "---\nnode9.html node2.html node7.html node1.html\n---\n# 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 chapter on Dynamic Loading for more info about\nthis.\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, add a line to the file\n``Modules/Setup`' describing your file:\n```text\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 rebuilt the ``Makefile`'\nthere by running `make Makefile`. (This is necessary each time\nyou change the ``Setup`' file.)\nIf your module requires additional libraries to link with, these can\nbe listed on the line in the ``Setup`' file as well, for instance:\n```text\nspam spammodule.o -lX11\n```\n---\nguido@cwi.nl", "python_version": "1.2", "length": 1213, "url": "https://docs.python.org/{python_version}/python-ext/node8.html"} {"title": "Calling Python Functions From C", "text": "---\nnode10.html node2.html node8.html node1.html\n---\n# 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`'.)\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\n`Py_INCREF()` it!) in a global variable --- or whereever you see fit.\nFor example, the following function might be part of a module\ndefinition:\n```text\nstatic PyObject *my_callback = NULL;\n\nstatic PyObject *\nmy_set_callback(dummy, arg)\nPyObject *dummy, *arg;\n{\nPy_XDECREF(my_callback); /* Dispose of previous callback */\nPy_XINCREF(arg); /* Add a reference to new callback */\nmy_callback = arg; /* Remember new callback */\n/* Boilerplate to return \"None\" */\nPy_INCREF(Py_None);\nreturn Py_None;\n}\n```\nThe macros `Py_XINCREF()` and `Py_XDECREF()` increment/decrement\nthe reference count of an object and are safe in the presence of\n`NULL` pointers. More info on them in the section on Reference\nCounts below.\nLater, when it is time to call the function, you call the C function\n`PyEval_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\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```\n`PyEval_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 raising\nan exception. If the C code that called `PyEval_CallObject()` is\ncalled from Python, it should now return an error indication to its\nPython caller, so the interpreter can print a stack trace, or the\ncalling Python code can handle the exception. If this is not possible\nor desirable, the exception should be cleared by calling\n`PyErr_Clear()`. For example:\n```text\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 `PyEval_CallObject()`.\nIn some cases the argument list is also provided by the Python\nprogram, through the same interface that specified the callback\nfunction. It can then be saved and used in the same manner as the\nfunction object. In other cases, you may have to construct a new\ntuple to pass as the argument list. The simplest way to do this is to\ncall `Py_BuildValue()`. For example, if you want to pass an integral\nevent code, you might use the following code:\n```text\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(argument)` immediately after the call,\nbefore the error check! Also note that strictly spoken this code is\nnot complete: `Py_BuildValue()` may run out of memory, and this should\nbe checked.\n---\nnode10.html node2.html node8.html node1.html\n---\n---\nguido@cwi.nl", "python_version": "1.2", "length": 4996, "url": "https://docs.python.org/{python_version}/python-ext/node9.html"} {"title": "__builtin__ -- Python library reference", "text": "__builtin__ -- Python library reference\nPrev: imp (imp.html)\nTop: Top (top.html)\n# 3.9. Built-in Module `__builtin__`\nThis module provides direct access to all `built-in' identifiers of\nPython; e.g. `__builtin__.open` is the full name for the built-in\nfunction `open`. See the section on Built-in Functions in the\nprevious chapter.", "python_version": "1.2", "length": 332, "url": "https://docs.python.org/{python_version}/python-lib/__builtin__.html"} {"title": "__main__ -- Python library reference", "text": "__main__ -- Python library reference\nPrev: __builtin__ (__builtin__.html)\nTop: Top (top.html)\n# 3.10. Built-in Module `__main__`\nThis module represents the (otherwise anonymous) scope in which the\ninterpreter's main program executes --- commands read either from\nstandard input or from a script file.", "python_version": "1.2", "length": 300, "url": "https://docs.python.org/{python_version}/python-lib/__main__.html"} {"title": "aifc -- Python library reference", "text": "aifc -- Python library reference\nPrev: imageop (imageop.html)\nTop: Top (top.html)\n# 12.3. Standard Module `aifc`\nThis module provides support for reading and writing AIFF and AIFF-C\nfiles. AIFF is Audio Interchange File Format, a format for storing\ndigital audio samples in a file. AIFF-C is a newer version of the\nformat that includes the ability to compress the audio data.\nAudio files have a number of parameters that describe the audio data.\nThe sampling rate or frame rate is the number of times per second the\nsound is sampled. The number of channels indicate if the audio is\nmono, stereo, or quadro. Each frame consists of one sample per\nchannel. The sample size is the size in bytes of each sample. Thus a\nframe consists of nchannels*samplesize bytes, and a\nsecond's worth of audio consists of\nnchannels*samplesize*framerate bytes.\nFor example, CD quality audio has a sample size of two bytes (16\nbits), uses two channels (stereo) and has a frame rate of 44,100\nframes/second. This gives a frame size of 4 bytes (2*2), and a\nsecond's worth occupies 2*2*44100 bytes, i.e. 176,400 bytes.\nModule `aifc` defines the following function:\nObjects returned by `aifc.open()` when a file is opened for\nreading have the following methods:\nObjects returned by `aifc.open()` when a file is opened for\nwriting have all the above methods, except for `readframes` and\n`setpos`. In addition the following methods exist. The\n`get` methods can only be called after the corresponding\n`set` methods have been called. Before the first\n`writeframes` or `writeframesraw`, all parameters except for\nthe number of frames must be filled in.", "python_version": "1.2", "length": 1623, "url": "https://docs.python.org/{python_version}/python-lib/aifc.html"} {"title": "al -- Python library reference", "text": "al -- Python library reference\nPrev: SGI IRIX Specific Services (sgi_irix_specific_services.html)\nTop: Top (top.html)\n# 16.1. Built-in Module `al`\nThis module provides access to the audio facilities of the SGI Indy\nand Indigo workstations. See section 3A of the IRIX man pages for\ndetails. You'll need to read those man pages to understand what these\nfunctions do! Some of the functions are not available in IRIX\nreleases before 4.0.5. Again, see the manual to check whether a\nspecific function is available on your platform.\nAll functions and methods defined in this module are equivalent to\nthe C functions with `AL' prefixed to their name.\nSymbolic constants from the C header file are defined\nin the standard module `AL`, see below.\nWarning: the current version of the audio library may dump core\nwhen bad argument values are passed rather than returning an error\nstatus. Unfortunately, since the precise circumstances under which\nthis may happen are undocumented and hard to check, the Python\ninterface can provide no protection against this kind of problems.\n(One example is specifying an excessive queue size --- there is no\ndocumented upper limit.)\nThe module defines the following functions:\n## Menu", "python_version": "1.2", "length": 1222, "url": "https://docs.python.org/{python_version}/python-lib/al.html"} {"title": "AL (uppercase) -- Python library reference", "text": "AL (uppercase) -- Python library reference\nPrev: al (al.html)\nTop: Top (top.html)\n# 16.2. Standard Module `AL`\nThis module defines symbolic constants needed to use the built-in\nmodule `al` (see above); they are equivalent to those defined in\nthe C header file except that the name prefix\n`AL_' is omitted. Read the module source for a complete list of\nthe defined names. Suggested use:", "python_version": "1.2", "length": 397, "url": "https://docs.python.org/{python_version}/python-lib/al__uppercase_.html"} {"title": "alias objects -- Python library reference", "text": "alias objects -- Python library reference\nPrev: FSSpec objects (fsspec_objects.html)\nTop: Top (top.html)\n## 14.6.2. alias objects\nNote that it is currently not possible to directly manipulate a resource\nas an alias object. Hence, after calling Update or after\nResolve indicates that the alias has changed the Python program\nis responsible for getting the data from the alias object and\nmodifying the resource.", "python_version": "1.2", "length": 409, "url": "https://docs.python.org/{python_version}/python-lib/alias_objects.html"} {"title": "array -- Python library reference", "text": "array -- Python library reference\nPrev: whrandom (whrandom.html)\nTop: Top (top.html)\n# 5.4. Built-in Module `array`\nThis module defines a new object type which can efficiently represent\nan array of basic values: characters, integers, floating point\nnumbers. Arrays are sequence types and behave very much like lists,\nexcept that the type of objects stored in them is constrained. The\ntype is specified at object creation time by using a type code,\nwhich is a single character. The following type codes are defined:\nThe actual representation of values is determined by the machine\narchitecture (strictly speaking, by the C implementation). The actual\nsize can be accessed through the itemsize attribute.\nSee also built-in module `struct`.\nThe module defines the following function:\nArray objects support the following data items and methods:\nWhen an array object is printed or converted to a string, it is\nrepresented as `array( typecode , initializer )`. The\ninitializer is omitted if the array is empty, otherwise it is a\nstring if the typecode is `'c'`, otherwise it is a list of\nnumbers. The string is guaranteed to be able to be converted back to\nan array with the same type and value using reverse quotes\n(````). Examples:", "python_version": "1.2", "length": 1230, "url": "https://docs.python.org/{python_version}/python-lib/array.html"} {"title": "Audio Device Objects -- Python library reference", "text": "Audio Device Objects -- Python library reference\nPrev: sunaudiodev (sunaudiodev.html)\nTop: Top (top.html)\n## 17.1.1. Audio Device Objects\nThe audio device objects are returned by `open` define the\nfollowing methods (except `control` objects which only provide\ngetinfo, setinfo and drain):\nThere is a companion module, `SUNAUDIODEV`, which defines useful\nsymbolic constants like `MIN_GAIN`, `MAX_GAIN`,\n`SPEAKER`, etc. The names of\nthe constants are the same names as used in the C include file\n, with the leading string `AUDIO_' stripped.\nUseability of the control device is limited at the moment, since there\nis no way to use the ``wait for something to happen'' feature the\ndevice provides.", "python_version": "1.2", "length": 707, "url": "https://docs.python.org/{python_version}/python-lib/audio_device_objects.html"} {"title": "audioop -- Python library reference", "text": "audioop -- Python library reference\nPrev: Multimedia Services (multimedia_services.html)\nTop: Top (top.html)\n# 12.1. Built-in Module `audioop`\nThe `audioop` module contains some useful operations on sound fragments.\nIt operates on sound fragments consisting of signed integer samples\n8, 16 or 32 bits wide, stored in Python strings. This is the same\nformat as used by the `al` and `sunaudiodev` modules. All\nscalar items are integers, unless specified otherwise.\nA few of the more complicated operations only take 16-bit samples,\notherwise the sample size (in bytes) is always a parameter of the operation.\nThe module defines the following variables and functions:\nNote that operations such as `mul` or `max` make no\ndistinction between mono and stereo fragments, i.e. all samples are\ntreated equal. If this is a problem the stereo fragment should be split\ninto two mono fragments first and recombined later. Here is an example\nof how to do that:\nIf you use the ADPCM coder to build network packets and you want your\nprotocol to be stateless (i.e. to be able to tolerate packet loss)\nyou should not only transmit the data but also the state. Note that\nyou should send the initial state (the one you passed to\n`lin2adpcm`) along to the decoder, not the final state (as returned by\nthe coder). If you want to use `struct` to store the state in\nbinary you can code the first element (the predicted value) in 16 bits\nand the second (the delta index) in 8.\nThe ADPCM coders have never been tried against other ADPCM coders,\nonly against themselves. It could well be that I misinterpreted the\nstandards in which case they will not be interoperable with the\nrespective standards.\nThe `find...` routines might look a bit funny at first sight.\nThey are primarily meant to do echo cancellation. A reasonably\nfast way to do this is to pick the most energetic piece of the output\nsample, locate that in the input sample and subtract the whole output\nsample from the input sample:", "python_version": "1.2", "length": 1969, "url": "https://docs.python.org/{python_version}/python-lib/audioop.html"} {"title": "Bit-string Operations -- Python library reference", "text": "Bit-string Operations -- Python library reference\nPrev: Numeric Types (numeric_types.html)\nTop: Top (top.html)\n### 2.1.4.1. Bit-string Operations on Integer Types\nPlain and long integer types support additional operations that make\nsense only for bit-strings. Negative numbers are treated as their 2's\ncomplement value (for long integers, this assumes a sufficiently large\nnumber of bits that no overflow occurs during the operation).\nThe priorities of the binary bit-wise operations are all lower than\nthe numeric operations and higher than the comparisons; the unary\noperation `~' has the same priority as the other unary numeric\noperations (`+' and `-').\nThis table lists the bit-string operations sorted in ascending\npriority (operations in the same box have the same priority):\nNotes:", "python_version": "1.2", "length": 790, "url": "https://docs.python.org/{python_version}/python-lib/bit-string_operations.html"} {"title": "Bitmap Objects -- Python library reference", "text": "Bitmap Objects -- Python library reference\nPrev: Menu Objects (menu_objects.html)\nTop: Top (top.html)\n## 15.1.5. Bitmap Objects\nA bitmap represents a rectangular array of bits.\nThe top left bit has coordinate (0, 0).\nA bitmap can be drawn with the `bitmap` method of a drawing object.\nBitmaps are currently not available on the Macintosh.\nThe following methods are defined:", "python_version": "1.2", "length": 373, "url": "https://docs.python.org/{python_version}/python-lib/bitmap_objects.html"} {"title": "Boolean Operations -- Python library reference", "text": "Boolean Operations -- Python library reference\nPrev: Truth Value Testing (truth_value_testing.html)\nTop: Top (top.html)\n## 2.1.2. Boolean Operations\nThese are the Boolean operations, ordered by ascending priority:\n Notes:", "python_version": "1.2", "length": 221, "url": "https://docs.python.org/{python_version}/python-lib/boolean_operations.html"} {"title": "Built-in Functions -- Python library reference", "text": "Built-in Functions -- Python library reference\nPrev: Exceptions (exceptions.html)\nTop: Top (top.html)\n# 2.3. Built-in Functions\nThe Python interpreter has a number of functions built into it that\nare always available. They are listed here in alphabetical order.\n## ---------- Footnotes ----------\n(1) (#footnoteref1)\nIt is used relatively rarely\nso does not warrant being made into a statement.\n(2) (#footnoteref2)\nThis is ugly --- the\nlanguage definition should require truncation towards zero.\n(3) (#footnoteref3)\nSpecifying a buffer size currently has no effect on systems\nthat don't have `setvbuf()`. The interface to specify the buffer\nsize is not done using a method that calls `setvbuf()`, because\nthat may dump core when called after any I/O has been performed, and\nthere's no reliable way to determine whether this is the case.\n(4) (#footnoteref4)\nIn the current implementation, local variable bindings\ncannot normally be affected this way, but variables retrieved from\nother scopes (e.g. modules) can be. This may change.", "python_version": "1.2", "length": 1032, "url": "https://docs.python.org/{python_version}/python-lib/built-in_functions.html"} {"title": "Built-in Objects -- Python library reference", "text": "Built-in Objects -- Python library reference\nPrev: Introduction (introduction.html)\nTop: Top (top.html)\n# 2. Built-in Types, Exceptions and Functions\nNames for built-in exceptions and functions are found in a separate\nsymbol table. This table is searched last when the interpreter looks\nup the meaning of a name, so local and global\nuser-defined names can override built-in names. Built-in types are\ndescribed together here for easy reference.(1) (#footnotetext1)\nThe tables in this chapter document the priorities of operators by\nlisting them in order of ascending priority (within a table) and\ngrouping operators that have the same priority in the same box.\nBinary operators of the same priority group from left to right.\n(Unary operators group from right to left, but there you have no real\nchoice.) See Chapter 5 of the Python Reference Manual for the\ncomplete picture on operator priorities.\n## Menu\n## ---------- Footnotes ----------\n(1) (#footnoteref1)\nMost descriptions sorely lack explanations of the exceptions\nthat may be raised --- this will be fixed in a future version of\nthis manual.", "python_version": "1.2", "length": 1101, "url": "https://docs.python.org/{python_version}/python-lib/built-in_objects.html"} {"title": "Calibration -- Python library reference", "text": "Calibration -- Python library reference\nPrev: Limitations (limitations.html)\nTop: Top (top.html)\n# 10.7. Calibration\nThe profiler class has a hard coded constant that is added to each\nevent handling time to compensate for the overhead of calling the time\nfunction, and socking away the results. The following procedure can\nbe used to obtain this constant for a given platform (see discussion\nin section Limitations above).\nThe argument to calibrate() is the number of times to try to do the\nsample calls to get the CPU times. If your computer is very\nfast, you might have to do:\nor even:\nThe object of this exercise is to get a fairly consistent result.\nWhen you have a consistent answer, you are ready to use that number in\nthe source code. For a Sun Sparcstation 1000 running Solaris 2.3, the\nmagical number is about .00053. If you have a choice, you are better\noff with a smaller constant, and your results will ``less often'' show\nup as negative in profile statistics.\nThe following shows how the trace_dispatch() method in the Profile\nclass should be modified to install the calibration constant on a Sun\nSparcstation 1000:\nNote that if there is no calibration constant, then the line\ncontaining the callibration constant should simply say:\nYou can also achieve the same results using a derived class (and the\nprofiler will actually run equally fast!!), but the above method is\nthe simplest to use. I could have made the profiler ``self\ncalibrating'', but it would have made the initialization of the\nprofiler class slower, and would have required some very fancy\ncoding, or else the use of a variable where the constant `.00053'\nwas placed in the code shown. This is a VERY critical\nperformance section, and there is no reason to use a variable lookup\nat this point, when a constant can be used.", "python_version": "1.2", "length": 1802, "url": "https://docs.python.org/{python_version}/python-lib/calibration.html"} {"title": "cd -- Python library reference", "text": "cd -- Python library reference\nPrev: AL (uppercase) (al__uppercase_.html)\nTop: Top (top.html)\n# 16.3. Built-in Module `cd`\nThis module provides an interface to the Silicon Graphics CD library.\nIt is available only on Silicon Graphics systems.\nThe way the library works is as follows. A program opens the CD-ROM\ndevice with `cd.open()` and creates a parser to parse the data\nfrom the CD with `cd.createparser()`. The object returned by\n`cd.open()` can be used to read data from the CD, but also to get\nstatus information for the CD-ROM device, and to get information about\nthe CD, such as the table of contents. Data from the CD is passed to\nthe parser, which parses the frames, and calls any callback\nfunctions that have previously been added.\nAn audio CD is divided into tracks or programs (the terms\nare used interchangeably). Tracks can be subdivided into\nindices. An audio CD contains a table of contents which\ngives the starts of the tracks on the CD. Index 0 is usually the\npause before the start of a track. The start of the track as given by\nthe table of contents is normally the start of index 1.\nPositions on a CD can be represented in two ways. Either a frame\nnumber or a tuple of three values, minutes, seconds and frames. Most\nfunctions use the latter representation. Positions can be both\nrelative to the beginning of the CD, and to the beginning of the\ntrack.\nModule `cd` defines the following functions and constants:\nThe module defines the following variables:\nThe following variables are states as returned by `getstatus`:\nPlayer objects (returned by `cd.open()`) have the following\nmethods:\nParser objects (returned by `cd.createparser()`) have the\nfollowing methods:", "python_version": "1.2", "length": 1686, "url": "https://docs.python.org/{python_version}/python-lib/cd.html"} {"title": "cgi -- Python library reference", "text": "cgi -- Python library reference\nPrev: Internet and WWW (internet_and_www.html)\nTop: Top (top.html)\n# 11.1. Standard Module `cgi`\nThis module makes it easy to write Python scripts that run in a WWW\nserver using the Common Gateway Interface. It was written by Michael\nMcLay and subsequently modified by Steve Majewski and Guido van\nRossum.\nWhen a WWW server finds that a URL contains a reference to a file in a\nparticular subdirectory (usually `/cgibin`), it runs the file as\na subprocess. Information about the request such as the full URL, the\noriginating host etc., is passed to the subprocess in the shell\nenvironment; additional input from the client may be read from\nstandard input. Standard output from the subprocess is sent back\nacross the network to the client as the response from the request.\nThe CGI protocol describes what the environment variables passed to\nthe subprocess mean and how the output should be formatted. The\nofficial reference documentation for the CGI protocol can be found on\nthe World-Wide Web at\n``. The\n`cgi` module was based on version 1.1 of the protocol and should\nalso work with version 1.0.\nThe `cgi` module defines several classes that make it easy to\naccess the information passed to the subprocess from a Python script;\nin particular, it knows how to parse the input sent by an HTML\n``form'' using either a POST or a GET request (these are alternatives\nfor submitting forms in the HTTP protocol).\nThe formatting of the output is so trivial that no additional support\nis needed. All you need to do is print a minimal set of MIME headers\ndescribing the output format, followed by a blank line and your actual\noutput. E.g. if you want to generate HTML, your script could start as\nfollows:\nThe server will add some header lines of its own, but it won't touch\nthe output following the header.\nThe `cgi` module defines the following functions:\nThe module defines the following classes. Since the base class\ninitializes itself by calling `parse()`, at most one instance of\nat most one of these classes should be created per script invocation:\n(It currently defines some more classes, but these are experimental\nand/or obsolescent, and are thus not documented --- see the source for\nmore informations.)\nThe module defines the following variable:\n## Menu", "python_version": "1.2", "length": 2337, "url": "https://docs.python.org/{python_version}/python-lib/cgi.html"} {"title": "CGI Example -- Python library reference", "text": "CGI Example -- Python library reference\nPrev: cgi (cgi.html)\nTop: Top (top.html)\n## 11.1.1. Example\nThis example assumes that you have a WWW server up and running,\ne.g. NCSA's `httpd`.\nPlace the following file in a convenient spot in the WWW server's\ndirectory tree. E.g., if you place it in the subdirectory test\nof the root directory and call it test.html, its URL will be\nhttp://yourservername/test/test.html.\nSelecting this file's URL from a forms-capable browser such as Mosaic\nor Netscape will bring up a simple form with two text input fields and\na ``submit'' button.\nBut wait. Before pressing ``submit'', a script that responds to the\nform must also be installed. The test file as shown assumes that the\nscript is called test.py and lives in the server's\n`cgi-bin` directory. Here's the test script:\nThe script should be made executable (`chmod +x script').\nIf the Python interpreter is not located at\n/usr/local/bin/python but somewhere else, the first line of the\nscript should be modified accordingly.\nNow that everything is installed correctly, we can try out the form.\nBring up the test form in your WWW browser, fill in a name and address\nin the form, and press the ``submit'' button. The script should now\nrun and its output is sent back to your browser. This should roughly\nlook as follows:\nTest Form Output\n- • Name: the name you entered\n• Address: the address you entered\nIf you didn't enter a name or address, the corresponding line will be\nmissing (since the browser doesn't send empty form fields to the\nserver).", "python_version": "1.2", "length": 1533, "url": "https://docs.python.org/{python_version}/python-lib/cgi_example.html"} {"title": "Classes and Instances -- Python library reference", "text": "Classes and Instances -- Python library reference\nPrev: Modules (modules.html)\nTop: Top (top.html)\n### 2.1.7.2. Classes and Class Instances\n(See Chapters 3 and 7 of the Python Reference Manual for these.)", "python_version": "1.2", "length": 204, "url": "https://docs.python.org/{python_version}/python-lib/classes_and_instances.html"} {"title": "Code Objects -- Python library reference", "text": "Code Objects -- Python library reference\nPrev: Methods (methods.html)\nTop: Top (top.html)\n### 2.1.7.5. Code Objects\nCode objects are used by the implementation to represent\n``pseudo-compiled'' executable Python code such as a function body.\nThey differ from function objects because they don't contain a\nreference to their global execution environment. Code objects are\nreturned by the built-in `compile()` function and can be\nextracted from function objects through their `func_code`\nattribute.\nA code object can be executed or evaluated by passing it (instead of a\nsource string) to the `exec` statement or the built-in\n`eval()` function.\n(See the Python Reference Manual for more info.)", "python_version": "1.2", "length": 690, "url": "https://docs.python.org/{python_version}/python-lib/code_objects.html"} {"title": "Comparisons -- Python library reference", "text": "Comparisons -- Python library reference\nPrev: Boolean Operations (boolean_operations.html)\nTop: Top (top.html)\n## 2.1.3. Comparisons\nComparison operations are supported by all objects. They all have the\nsame priority (which is higher than that of the Boolean operations).\nComparisons can be chained arbitrarily, e.g. `x < y <= z` is\nequivalent to `x < y and y <= z`, except that `y` is\nevaluated only once (but in both cases `z` is not evaluated at\nall when `x < y` is found to be false).\nThis table summarizes the comparison operations:\nNotes:\nObjects of different types, except different numeric types, never\ncompare equal; such objects are ordered consistently but arbitrarily\n(so that sorting a heterogeneous array yields a consistent result).\nFurthermore, some types (e.g., windows) support only a degenerate\nnotion of comparison where any two objects of that type are unequal.\nAgain, such objects are ordered arbitrarily but consistently.\n(Implementation note: objects of different types except numbers are\nordered by their type names; objects of the same types that don't\nsupport proper comparison are ordered by their address.)\nTwo more operations with the same syntactic priority, `in` and\n`not in`, are supported only by sequence types (below).", "python_version": "1.2", "length": 1255, "url": "https://docs.python.org/{python_version}/python-lib/comparisons.html"} {"title": "Concept Index -- Python library reference", "text": "Concept Index -- Python library reference\nPrev: Module Index (module_index.html)\nTop: Top (top.html)\n# Concept Index", "python_version": "1.2", "length": 116, "url": "https://docs.python.org/{python_version}/python-lib/concept_index.html"} {"title": "Configuration Objects -- Python library reference", "text": "Configuration Objects -- Python library reference\nPrev: al (al.html)\nTop: Top (top.html)\n## 16.1.1. Configuration Objects\nConfiguration objects (returned by `al.newconfig()` have the\nfollowing methods:", "python_version": "1.2", "length": 201, "url": "https://docs.python.org/{python_version}/python-lib/configuration_objects.html"} {"title": "connection object -- Python library reference", "text": "connection object -- Python library reference\nPrev: ctb (ctb.html)\nTop: Top (top.html)\n## 14.3.1. connection object\nFor all connection methods that take a timeout argument, a value\nof `-1` is indefinite, meaning that the command runs to completion.", "python_version": "1.2", "length": 248, "url": "https://docs.python.org/{python_version}/python-lib/connection_object.html"} {"title": "console window object -- Python library reference", "text": "console window object -- Python library reference\nPrev: macconsole options object (macconsole_options_object.html)\nTop: Top (top.html)\n## 14.4.2. console window object", "python_version": "1.2", "length": 167, "url": "https://docs.python.org/{python_version}/python-lib/console_window_object.html"} {"title": "copy -- Python library reference", "text": "copy -- Python library reference\nPrev: shelve (shelve.html)\nTop: Top (top.html)\n# 3.6. Standard Module `copy`\nThis module provides generic (shallow and deep) copying operations.\nInterface summary:\nFor module specific errors, `copy.error` is raised.\nThe difference between shallow and deep copying is only relevant for\ncompound objects (objects that contain other objects, like lists or\nclass instances):\n- • A shallow copy constructs a new compound object and then (to the\nextent possible) inserts references into it to the objects found\nin the original.\n• A deep copy constructs a new compound object and then,\nrecursively, inserts copies into it of the objects found in the\noriginal.\nTwo problems often exist with deep copy operations that don't exist\nwith shallow copy operations:\n- • Recursive objects (compound objects that, directly or indirectly,\ncontain a reference to themselves) may cause a recursive loop.\n• Because deep copy copies everything it may copy too much, e.g.\nadministrative data structures that should be shared even between\ncopies.\nPython's `deepcopy()` operation avoids these problems by:\n- • keeping a table of objects already copied during the current\ncopying pass; and\n• letting user-defined classes override the copying operation or the\nset of components copied.\nThis version does not copy types like module, class, function, method,\nnor stack trace, stack frame, nor file, socket, window, nor array, nor\nany similar types.\nClasses can use the same interfaces to control copying that they use\nto control pickling: they can define methods called\n`__getinitargs__()`, `__getstate__()` and\n`__setstate__()`. See the description of module `pickle`\nfor information on these methods.", "python_version": "1.2", "length": 1706, "url": "https://docs.python.org/{python_version}/python-lib/copy.html"} {"title": "Cryptographic Services -- Python library reference", "text": "Cryptographic Services -- Python library reference\nPrev: Multimedia Services (multimedia_services.html)\nTop: Top (top.html)\n# 13. Cryptographic Services\nThe modules described in this chapter implement various algorithms of\na cryptographic nature. They are available at the discretion of the\ninstallation. Here's an overview:\nHardcore cypherpunks will probably find the Python Cryptography Kit of\nfurther interest; the package adds built-in modules for DES and IDEA\nencryption, and provides a Python module for reading and decrypting\nPGP files. The Python Cryptography Kit is not distributed with Python\nbut available separately. See the URL\nhttp://www.cs.mcgill.ca/%7Efnord/crypt.html for more information.\n## Menu", "python_version": "1.2", "length": 716, "url": "https://docs.python.org/{python_version}/python-lib/cryptographic_services.html"} {"title": "ctb -- Python library reference", "text": "ctb -- Python library reference\nPrev: macpath (macpath.html)\nTop: Top (top.html)\n# 14.3. Built-in Module `ctb`\nThis module provides a partial interface to the Macintosh\nCommunications Toolbox. Currently, only Connection Manager tools are\nsupported. It may not be available in all Mac Python versions.\n## Menu", "python_version": "1.2", "length": 309, "url": "https://docs.python.org/{python_version}/python-lib/ctb.html"} {"title": "dbm -- Python library reference", "text": "dbm -- Python library reference\nPrev: grp (grp.html)\nTop: Top (top.html)\n# 8.5. Built-in Module `dbm`\nDbm provides python programs with an interface to the unix `ndbm`\ndatabase library. Dbm objects are of the mapping type, so they can be\nhandled just like objects of the built-in dictionary type,\nexcept that keys and values are always strings, and printing a dbm\nobject doesn't print the keys and values.\nThe module defines the following constant and functions:", "python_version": "1.2", "length": 463, "url": "https://docs.python.org/{python_version}/python-lib/dbm.html"} {"title": "Debugger Commands -- Python library reference", "text": "Debugger Commands -- Python library reference\nPrev: The Python Debugger (the_python_debugger.html)\nTop: Top (top.html)\n# 9.1. Debugger Commands\nThe debugger recognizes the following commands. Most commands can be\nabbreviated to one or two letters; e.g. ```h(elp)`'' means that\neither ```h`'' or ```help`'' can be used to enter the help\ncommand (but not ```he`'' or ```hel`'', nor ```H`'' or\n```Help` or ```HELP`''). Arguments to commands must be\nseparated by whitespace (spaces or tabs). Optional arguments are\nenclosed in square brackets (```[]`'') in the command syntax; the\nsquare brackets must not be typed. Alternatives in the command syntax\nare separated by a vertical bar (```|`'').\n\nEntering a blank line repeats the last command entered. Exception: if\nthe last command was a ```list`'' command, the next 11 lines are\nlisted.\n\nCommands that the debugger doesn't recognize are assumed to be Python\nstatements and are executed in the context of the program being\ndebugged. Python statements can also be prefixed with an exclamation\npoint (```!`''). This is a powerful way to inspect the program\nbeing debugged; it is even possible to change a variable or call a\nfunction. When an\nexception occurs in such a statement, the exception name is printed\nbut the debugger's state is not changed.", "python_version": "1.2", "length": 1298, "url": "https://docs.python.org/{python_version}/python-lib/debugger_commands.html"} {"title": "Deterministic Profiling -- Python library reference", "text": "Deterministic Profiling -- Python library reference\nPrev: Instant Users Manual (instant_users_manual.html)\nTop: Top (top.html)\n# 10.4. What Is Deterministic Profiling?\nDeterministic profiling is meant to reflect the fact that all\nfunction call, function return, and exception events\nare monitored, and precise timings are made for the intervals between\nthese events (during which time the user's code is executing). In\ncontrast, statistical profiling (which is not done by this\nmodule) randomly samples the effective instruction pointer, and\ndeduces where time is being spent. The latter technique traditionally\ninvolves less overhead (as the code does not need to be instrumented),\nbut provides only relative indications of where time is being spent.\nIn Python, since there is an interpreter active during execution, the\npresence of instrumented code is not required to do deterministic\nprofiling. Python automatically provides a hook (optional\ncallback) for each event. In addition, the interpreted nature of\nPython tends to add so much overhead to execution, that deterministic\nprofiling tends to only add small processing overhead in typical\napplications. The result is that deterministic profiling is not that\nexpensive, yet provides extensive run time statistics about the\nexecution of a Python program.\nCall count statistics can be used to identify bugs in code (surprising\ncounts), and to identify possible inline-expansion points (high call\ncounts). Internal time statistics can be used to identify ``hot\nloops'' that should be carefully optimized. Cumulative time\nstatistics should be used to identify high level errors in the\nselection of algorithms. Note that the unusual handling of cumulative\ntimes in this profiler allows statistics for recursive implementations\nof algorithms to be directly compared to iterative implementations.", "python_version": "1.2", "length": 1847, "url": "https://docs.python.org/{python_version}/python-lib/deterministic_profiling.html"} {"title": "dnr result object -- Python library reference", "text": "dnr result object -- Python library reference\nPrev: macdnr (macdnr.html)\nTop: Top (top.html)\n## 14.5.1. dnr result object\nSince the DNR calls all execute asynchronously you do not get the\nresults back immediately. Instead, you get a dnr result object. You\ncan check this object to see whether the query is complete, and access\nits attributes to obtain the information when it is.\nAlternatively, you can also reference the result attributes directly,\nthis will result in an implicit wait for the query to complete.\nThe rtnCode and cname attributes are always available, the\nothers depend on the type of query (address, hinfo or mx).\nThe simplest way to use the module to convert names to dotted-decimal\nstrings, without worrying about idle time, etc:", "python_version": "1.2", "length": 751, "url": "https://docs.python.org/{python_version}/python-lib/dnr_result_object.html"} {"title": "Drawing Objects -- Python library reference", "text": "Drawing Objects -- Python library reference\nPrev: Window Objects (window_objects.html)\nTop: Top (top.html)\n## 15.1.3. Drawing Objects\nDrawing objects are created exclusively by the window method\n`begindrawing()`.\nOnly one drawing object can exist at any given time; the drawing object\nmust be deleted to finish drawing.\nNo drawing object may exist when\n`stdwin.getevent()`\nis called.\nDrawing objects have the following methods:", "python_version": "1.2", "length": 427, "url": "https://docs.python.org/{python_version}/python-lib/drawing_objects.html"} {"title": "Examples -- Python library reference", "text": "Examples -- Python library reference\nPrev: imp (imp.html)\nTop: Top (top.html)\n## 3.8.1. Examples\nThe following function emulates the default import statement:", "python_version": "1.2", "length": 158, "url": "https://docs.python.org/{python_version}/python-lib/examples.html"} {"title": "Exceptions -- Python library reference", "text": "Exceptions -- Python library reference\nPrev: Types (types.html)\nTop: Top (top.html)\n# 2.2. Built-in Exceptions\nExceptions are string objects. Two distinct string objects with the\nsame value are different exceptions. This is done to force programmers\nto use exception names rather than their string value when specifying\nexception handlers. The string value of all built-in exceptions is\ntheir name, but this is not a requirement for user-defined exceptions\nor exceptions defined by library modules.\nThe following exceptions can be generated by the interpreter or\nbuilt-in functions. Except where mentioned, they have an `associated\nvalue' indicating the detailed cause of the error. This may be a\nstring or a tuple containing several items of information (e.g., an\nerror code and a string explaining the code).\nUser code can raise built-in exceptions. This can be used to test an\nexception handler or to report an error condition `just like' the\nsituation in which the interpreter raises the same exception; but\nbeware that there is nothing to prevent user code from raising an\ninappropriate error.", "python_version": "1.2", "length": 1101, "url": "https://docs.python.org/{python_version}/python-lib/exceptions.html"} {"title": "fcntl -- Python library reference", "text": "fcntl -- Python library reference\nPrev: TERMIOS (termios.html)\nTop: Top (top.html)\n# 8.9. Built-in Module `fcntl`\nThis module performs file control and I/O control on file descriptors.\nIt is an interface to the fcntl() and ioctl() UNIX routines.\nFile descriptors can be obtained with the fileno() method of a\nfile or socket object.\nThe module defines the following functions:\nIf the library modules `FCNTL` or `IOCTL` are missing, you\ncan find the opcodes in the C include files `sys/fcntl` and\n`sys/ioctl`. You can create the modules yourself with the h2py\nscript, found in the `Demo/scripts` directory.\nExamples (all on a SVR4 compliant system):\nNote that in the first example the return value variable `rv` will\nhold an integer value; in the second example it will hold a string\nvalue.", "python_version": "1.2", "length": 788, "url": "https://docs.python.org/{python_version}/python-lib/fcntl.html"} {"title": "File Objects -- Python library reference", "text": "File Objects -- Python library reference\nPrev: The Null Object (the_null_object.html)\nTop: Top (top.html)\n### 2.1.7.8. File Objects\nFile objects are implemented using C's `stdio` package and can be\ncreated with the built-in function `open()` described under\nBuilt-in Functions below. They are also returned by some other\nbuilt-in functions and methods, e.g. `posix.popen()` and\n`posix.fdopen()` and the `makefile()` method of socket\nobjects.\nWhen a file operation fails for an I/O-related reason, the exception\n`IOError` is raised. This includes situations where the\noperation is not defined for some reason, like `seek()` on a tty\ndevice or writing a file opened for reading.\nFiles have the following methods:\n## ---------- Footnotes ----------\n(1) (#footnoteref1)\nThe advantage of leaving the newline on is that an empty string\ncan be returned to mean EOF without being ambiguous. Another\nadvantage is that (in cases where it might matter, e.g. if you\nwant to make an exact copy of a file while scanning its lines)\nyou can tell whether the last line of a file ended in a newline\nor not (yes this happens!).", "python_version": "1.2", "length": 1110, "url": "https://docs.python.org/{python_version}/python-lib/file_objects.html"} {"title": "fl -- Python library reference", "text": "fl -- Python library reference\nPrev: cd (cd.html)\nTop: Top (top.html)\n# 16.4. Built-in Module `fl`\nThis module provides an interface to the FORMS Library by Mark\nOvermars. The source for the library can be retrieved by anonymous\nftp from host `ftp.cs.ruu.nl', directory SGI/FORMS. It\nwas last tested with version 2.0b.\nMost functions are literal translations of their C equivalents,\ndropping the initial `fl_' from their name. Constants used by\nthe library are defined in module `FL` described below.\nThe creation of objects is a little different in Python than in C:\ninstead of the `current form' maintained by the library to which new\nFORMS objects are added, all functions that add a FORMS object to a\nform are methods of the Python object representing the form.\nConsequently, there are no Python equivalents for the C functions\n`fl_addto_form` and `fl_end_form`, and the equivalent of\n`fl_bgn_form` is called `fl.make_form`.\nWatch out for the somewhat confusing terminology: FORMS uses the word\nobject for the buttons, sliders etc. that you can place in a form.\nIn Python, `object' means any value. The Python interface to FORMS\nintroduces two new Python object types: form objects (representing an\nentire form) and FORMS objects (representing one button, slider etc.).\nHopefully this isn't too confusing...\nThere are no `free objects' in the Python interface to FORMS, nor is\nthere an easy way to add object classes written in Python. The FORMS\ninterface to GL event handling is available, though, so you can mix\nFORMS with pure GL windows.\nPlease note: importing `fl` implies a call to the GL function\n`foreground()` and to the FORMS routine `fl_init()`.\n## Menu", "python_version": "1.2", "length": 1670, "url": "https://docs.python.org/{python_version}/python-lib/fl.html"} {"title": "FL (uppercase) -- Python library reference", "text": "FL (uppercase) -- Python library reference\nPrev: fl (fl.html)\nTop: Top (top.html)\n# 16.5. Standard Module `FL`\nThis module defines symbolic constants needed to use the built-in\nmodule `fl` (see above); they are equivalent to those defined in\nthe C header file except that the name prefix\n`FL_' is omitted. Read the module source for a complete list of\nthe defined names. Suggested use:", "python_version": "1.2", "length": 397, "url": "https://docs.python.org/{python_version}/python-lib/fl__uppercase_.html"} {"title": "FL Functions -- Python library reference", "text": "FL Functions -- Python library reference\nPrev: fl (fl.html)\nTop: Top (top.html)\n## 16.4.1. Functions Defined in Module `fl`\nModule `fl` defines the following functions. For more information\nabout what they do, see the description of the equivalent C function\nin the FORMS documentation:", "python_version": "1.2", "length": 287, "url": "https://docs.python.org/{python_version}/python-lib/fl_functions.html"} {"title": "flp -- Python library reference", "text": "flp -- Python library reference\nPrev: FL (uppercase) (fl__uppercase_.html)\nTop: Top (top.html)\n# 16.6. Standard Module `flp`\nThis module defines functions that can read form definitions created\nby the `form designer' (`fdesign`) program that comes with the\nFORMS library (see module `fl` above).\nFor now, see the file flp.doc in the Python library source\ndirectory for a description.\nXXX A complete description should be inserted here!", "python_version": "1.2", "length": 435, "url": "https://docs.python.org/{python_version}/python-lib/flp.html"} {"title": "fm -- Python library reference", "text": "fm -- Python library reference\nPrev: flp (flp.html)\nTop: Top (top.html)\n# 16.7. Built-in Module `fm`\nThis module provides access to the IRIS Font Manager library.\nIt is available only on Silicon Graphics machines.\nSee also: 4Sight User's Guide, Section 1, Chapter 5: Using the IRIS\nFont Manager.\nThis is not yet a full interface to the IRIS Font Manager.\nAmong the unsupported features are: matrix operations; cache\noperations; character operations (use string operations instead); some\ndetails of font info; individual glyph metrics; and printer matching.\nIt supports the following operations:\nFont handle objects support the following operations:", "python_version": "1.2", "length": 648, "url": "https://docs.python.org/{python_version}/python-lib/fm.html"} {"title": "Form Objects -- Python library reference", "text": "Form Objects -- Python library reference\nPrev: FL Functions (fl_functions.html)\nTop: Top (top.html)\n## 16.4.2. Form Objects\nForm objects (returned by `fl.make_form()` above) have the\nfollowing methods. Each method corresponds to a C function whose name\nis prefixed with `fl_'; and whose first argument is a form\npointer; please refer to the official FORMS documentation for\ndescriptions.\nAll the `add_...' functions return a Python object representing\nthe FORMS object. Methods of FORMS objects are described below. Most\nkinds of FORMS object also have some methods specific to that kind;\nthese methods are listed here.\nForm objects have the following data attributes; see the FORMS\ndocumentation:", "python_version": "1.2", "length": 698, "url": "https://docs.python.org/{python_version}/python-lib/form_objects.html"} {"title": "FORMS Objects -- Python library reference", "text": "FORMS Objects -- Python library reference\nPrev: Form Objects (form_objects.html)\nTop: Top (top.html)\n## 16.4.3. FORMS Objects\nBesides methods specific to particular kinds of FORMS objects, all\nFORMS objects also have the following methods:\nFORMS objects have these data attributes; see the FORMS documentation:", "python_version": "1.2", "length": 310, "url": "https://docs.python.org/{python_version}/python-lib/forms_objects.html"} {"title": "FSSpec objects -- Python library reference", "text": "FSSpec objects -- Python library reference\nPrev: macfs (macfs.html)\nTop: Top (top.html)\n## 14.6.1. FSSpec objects", "python_version": "1.2", "length": 113, "url": "https://docs.python.org/{python_version}/python-lib/fsspec_objects.html"} {"title": "FTP Objects -- Python library reference", "text": "FTP Objects -- Python library reference\nPrev: ftplib (ftplib.html)\nTop: Top (top.html)\n## 11.4.1. FTP Objects\nFTP instances have the following methods:", "python_version": "1.2", "length": 151, "url": "https://docs.python.org/{python_version}/python-lib/ftp_objects.html"} {"title": "ftplib -- Python library reference", "text": "ftplib -- Python library reference\nPrev: httplib (httplib.html)\nTop: Top (top.html)\n# 11.4. Standard Module `ftplib`\nThis module defines the class `FTP` and a few related items. The\n`FTP` class implements the client side of the FTP protocol. You\ncan use this to write Python programs that perform a variety of\nautomated FTP jobs, such as mirroring other ftp servers. It is also\nused bu the module `urllib` to handle URLs that use FTP. For\nmore information on FTP (File Transfer Protocol), see Internet RFC\n959.\nHere's a sample session using the `ftplib` module:\nThe module defines the following items:\n## Menu", "python_version": "1.2", "length": 613, "url": "https://docs.python.org/{python_version}/python-lib/ftplib.html"} {"title": "Functions -- Python library reference", "text": "Functions -- Python library reference\nPrev: Classes and Instances (classes_and_instances.html)\nTop: Top (top.html)\n### 2.1.7.3. Functions\nFunction objects are created by function definitions. The only\noperation on a function object is to call it:\n`func ( argument-list )`.\nThere are really two flavors of function objects: built-in functions\nand user-defined functions. Both support the same operation (to call\nthe function), but the implementation is different, hence the\ndifferent object types.\nThe implementation adds two special read-only attributes:\n`f .func_code` is a function's code object (see below) and\n`f .func_globals` is the dictionary used as the function's\nglobal name space (this is the same as `m .__dict__` where\nm is the module in which the function f was defined).", "python_version": "1.2", "length": 786, "url": "https://docs.python.org/{python_version}/python-lib/functions.html"} {"title": "gdbm -- Python library reference", "text": "gdbm -- Python library reference\nPrev: dbm (dbm.html)\nTop: Top (top.html)\n# 8.6. Built-in Module `gdbm`\nGdbm provides python programs with an interface to the GNU `gdbm`\ndatabase library. Gdbm objects are of the mapping type, so they can be\nhandled just like objects of the built-in dictionary type,\nexcept that keys and values are always strings, and printing a gdbm\nobject doesn't print the keys and values.\nThe module is based on the Dbm module, modified to use GDBM instead.\nThe module defines the following constant and functions:", "python_version": "1.2", "length": 536, "url": "https://docs.python.org/{python_version}/python-lib/gdbm.html"} {"title": "Generic Operating System Services -- Python library reference", "text": "Generic Operating System Services -- Python library reference\nPrev: Miscellaneous Services (miscellaneous_services.html)\nTop: Top (top.html)\n# 6. Generic Operating System Services\nThe modules described in this chapter provide interfaces to operating\nsystem features that are available on (almost) all operating systems,\nsuch as files and a clock. The interfaces are generally modelled\nafter the UNIX or C interfaces but they are available on most other\nsystems as well. Here's an overview:\n## Menu", "python_version": "1.2", "length": 499, "url": "https://docs.python.org/{python_version}/python-lib/generic_operating_system_services.html"} {"title": "getopt -- Python library reference", "text": "getopt -- Python library reference\nPrev: time (time.html)\nTop: Top (top.html)\n# 6.3. Standard Module `getopt`\nThis module helps scripts to parse the command line arguments in\n`sys.argv`.\nIt uses the same conventions as the UNIX\n`getopt()`\nfunction (including the special meanings of arguments of the form\n`-' and `--').\nIt defines the function\n`getopt.getopt(args, options)`\nand the exception\n`getopt.error`.\nThe first argument to\n`getopt()`\nis the argument list passed to the script with its first element\nchopped off (i.e.,\n`sys.argv[1:]`).\nThe second argument is the string of option letters that the\nscript wants to recognize, with options that require an argument\nfollowed by a colon (i.e., the same format that UNIX\n`getopt()`\nuses).\nThe return value consists of two elements: the first is a list of\noption-and-value pairs; the second is the list of program arguments\nleft after the option list was stripped (this is a trailing slice of the\nfirst argument).\nEach option-and-value pair returned has the option as its first element,\nprefixed with a hyphen (e.g.,\n`'-x'`),\nand the option argument as its second element, or an empty string if the\noption has no argument.\nThe options occur in the list in the same order in which they were\nfound, thus allowing multiple occurrences.\nExample:\nThe exception\n`getopt.error = 'getopt error'`\nis raised when an unrecognized option is found in the argument list or\nwhen an option requiring an argument is given none.\nThe argument to the exception is a string indicating the cause of the\nerror.", "python_version": "1.2", "length": 1537, "url": "https://docs.python.org/{python_version}/python-lib/getopt.html"} {"title": "gl -- Python library reference", "text": "gl -- Python library reference\nPrev: fm (fm.html)\nTop: Top (top.html)\n# 16.8. Built-in Module `gl`\nThis module provides access to the Silicon Graphics\nGraphics Library.\nIt is available only on Silicon Graphics machines.\nWarning:\nSome illegal calls to the GL library cause the Python interpreter to dump\ncore.\nIn particular, the use of most GL calls is unsafe before the first\nwindow is opened.\nThe module is too large to document here in its entirety, but the\nfollowing should help you to get started.\nThe parameter conventions for the C functions are translated to Python as\nfollows:\n- • All (short, long, unsigned) int values are represented by Python\nintegers.\n• All float and double values are represented by Python floating point\nnumbers.\nIn most cases, Python integers are also allowed.\n• All arrays are represented by one-dimensional Python lists.\nIn most cases, tuples are also allowed.\n• All string and character arguments are represented by Python strings,\nfor instance,\n`winopen('Hi There!')`\nand\n`rotate(900, 'z')`.\n• All (short, long, unsigned) integer arguments or return values that are\nonly used to specify the length of an array argument are omitted.\nFor example, the C call\nis translated to Python as\n• Output arguments are omitted from the argument list; they are\ntransmitted as function return values instead.\nIf more than one value must be returned, the return value is a tuple.\nIf the C function has both a regular return value (that is not omitted\nbecause of the previous rule) and an output argument, the return value\ncomes first in the tuple.\nExamples: the C call\nis translated to Python as\nThe following functions are non-standard or have special argument\nconventions:\nHere is a tiny but complete example GL program in Python:", "python_version": "1.2", "length": 1752, "url": "https://docs.python.org/{python_version}/python-lib/gl.html"} {"title": "GL and DEVICE -- Python library reference", "text": "GL and DEVICE -- Python library reference\nPrev: gl (gl.html)\nTop: Top (top.html)\n# 16.9. Standard Modules `GL` and `DEVICE`\nThese modules define the constants used by the Silicon Graphics\nGraphics Library\nthat C programmers find in the header files\n\nand\n.\nRead the module source files for details.", "python_version": "1.2", "length": 319, "url": "https://docs.python.org/{python_version}/python-lib/gl_and_device.html"} {"title": "gopherlib -- Python library reference", "text": "gopherlib -- Python library reference\nPrev: ftplib (ftplib.html)\nTop: Top (top.html)\n# 11.5. Standard Module `gopherlib`\nThis module provides a minimal implementation of client side of the\nthe Gopher protocol. It is used by the module `urllib` to handle\nURLs that use the Gopher protocol.\nThe module defines the following functions:\nNote that the data returned by the Gopher server can be of any type,\ndepending on the first character of the selector string. If the data\nis text (first character of the selector is `0'), lines are\nterminated by CRLF, and the data is terminated by a line consisting of\na single `.', and a leading `.' should be stripped from\nlines that begin with `..'. Directory listings (first charactger\nof the selector is `1') are transferred using the same protocol.", "python_version": "1.2", "length": 788, "url": "https://docs.python.org/{python_version}/python-lib/gopherlib.html"} {"title": "grp -- Python library reference", "text": "grp -- Python library reference\nPrev: pwd (pwd.html)\nTop: Top (top.html)\n# 8.4. Built-in Module `grp`\nThis module provides access to the UNIX group database.\nIt is available on all UNIX versions.\nGroup database entries are reported as 4-tuples containing the\nfollowing items from the group database (see ), in order:\n`gr_name`,\n`gr_passwd`,\n`gr_gid`,\n`gr_mem`.\nThe gid is an integer, name and password are strings, and the member\nlist is a list of strings.\n(Note that most users are not explicitly listed as members of the\ngroup they are in according to the password database.)\nAn exception is raised if the entry asked for cannot be found.\nIt defines the following items:", "python_version": "1.2", "length": 679, "url": "https://docs.python.org/{python_version}/python-lib/grp.html"} {"title": "HotProfile Class -- Python library reference", "text": "HotProfile Class -- Python library reference\nPrev: OldProfile Class (oldprofile_class.html)\nTop: Top (top.html)\n## 10.8.2. HotProfile Class\nThis profiler is the fastest derived profile example. It does not\ncalculate caller-callee relationships, and does not calculate\ncumulative time under a function. It only calculates time spent in a\nfunction, so it runs very quickly (re: very low overhead). In truth,\nthe basic profiler is so fast, that is probably not worth the savings\nto give up the data, but this class still provides a nice example.", "python_version": "1.2", "length": 545, "url": "https://docs.python.org/{python_version}/python-lib/hotprofile_class.html"} {"title": "How It Works -- Python library reference", "text": "How It Works -- Python library reference\nPrev: Debugger Commands (debugger_commands.html)\nTop: Top (top.html)\n# 9.2. How It Works\nSome changes were made to the interpreter:\n- • sys.settrace(func) sets the global trace function\n• there can also a local trace function (see later)\nTrace functions have three arguments: (frame, event, arg)\nA trace function should return a new trace function or None.\nClass methods are accepted (and most useful!) as trace methods.\nThe events have the following meaning:\nNote that as an exception is propagated down the chain of callers, an\n`'exception'` event is generated at each level.\nStack frame objects have the following read-only attributes:\nCode objects have the following read-only attributes:", "python_version": "1.2", "length": 733, "url": "https://docs.python.org/{python_version}/python-lib/how_it_works.html"} {"title": "htmllib -- Python library reference", "text": "htmllib -- Python library reference\nPrev: urlparse (urlparse.html)\nTop: Top (top.html)\n# 11.8. Standard Module `htmllib`\nThis module defines a number of classes which can serve as a basis for\nparsing text files formatted in HTML (HyperText Mark-up Language).\nThe classes are not directly concerned with I/O --- the have to be fed\ntheir input in string form, and will make calls to methods of a\n``formatter'' object in order to produce output. The classes are\ndesigned to be used as base classes for other classes in order to add\nfunctionality, and allow most of their methods to be extended or\noverridden. In turn, the classes are derived from and extend the\nclass `SGMLParser` defined in module `sgmllib`.\nThe following is a summary of the interface defined by\n`sgmllib.SGMLParser`:\n- • The interface to feed data to an instance is through the `feed()`\nmethod, which takes a string argument. This can be called with as\nlittle or as much text at a time as desired;\n`p.feed(a); p.feed(b)` has the same effect as `p.feed(a+b)`.\nWhen the data contains complete\nHTML elements, these are processed immediately; incomplete elements\nare saved in a buffer. To force processing of all unprocessed data,\ncall the `close()` method.\nExample: to parse the entire contents of a file, do*\n`parser.feed(open(file).read()); parser.close()`.\n• The interface to define semantics for HTML tags is very simple: derive\na class and define methods called `start_ tag ()`,\n`end_ tag ()`, or `do_ tag ()`. The parser will\ncall these at appropriate moments: `start_ tag` or\n`do_ tag` is called when an opening tag of the form\n`< tag ...>` is encountered; `end_ tag` is called\nwhen a closing tag of the form `< tag >` is encountered. If\nan opening tag requires a corresponding closing tag, like `

`\n... `

`, the class should define the `start_ tag`\nmethod; if a tag requires no closing tag, like `

`, the class\nshould define the `do_ tag` method.\nThe module defines the following classes:\nInstances of `CollectingParser` (and thus also instances of\n`FormattingParser` and `AnchoringParser`) have the following\ninstance variables:\nThe `anchors`, `anchornames` and `anchortypes` lists\nare ``parallel arrays'': items in these lists with the same index\npertain to the same anchor. Missing attributes default to the empty\nstring. Anchors with neither a `HREF` nor a `NAME`\nattribute are not entered in these lists at all.\nThe module also defines a number of style sheet classes. These should\nnever be instantiated --- their class variables are the only behavior\nrequired. Note that style sheets are specifically designed for a\nparticular formatter implementation. The currently defined style\nsheets are:\nStyle sheets have the following class variables:\nAlthough no documented implementation of a formatter exists, the\n`FormattingParser` class assumes that formatters have a\ncertain interface. This interface requires the following methods:\nA sample formatter implementation can be found in the module\n`fmt`, which in turn uses the module `Para`. These modules are\nnot intended as standard library modules; they are available as an\nexample of how to write a formatter.", "python_version": "1.2", "length": 3145, "url": "https://docs.python.org/{python_version}/python-lib/htmllib.html"} {"title": "HTTP Example -- Python library reference", "text": "HTTP Example -- Python library reference\nPrev: HTTP Objects (http_objects.html)\nTop: Top (top.html)\n## 11.3.2. Example\nHere is an example session:", "python_version": "1.2", "length": 146, "url": "https://docs.python.org/{python_version}/python-lib/http_example.html"} {"title": "HTTP Objects -- Python library reference", "text": "HTTP Objects -- Python library reference\nPrev: httplib (httplib.html)\nTop: Top (top.html)\n## 11.3.1. HTTP Objects\n`HTTP` instances have the following methods:", "python_version": "1.2", "length": 158, "url": "https://docs.python.org/{python_version}/python-lib/http_objects.html"} {"title": "httplib -- Python library reference", "text": "httplib -- Python library reference\nPrev: urllib (urllib.html)\nTop: Top (top.html)\n# 11.3. Standard Module `httplib`\nThis module defines a class which implements the client side of the\nHTTP protocol. It is normally not used directly --- the module\n`urllib` uses it to handle URLs that use HTTP.\nThe module defines one class, `HTTP`. An `HTTP` instance\nrepresents one transaction with an HTTP server. It should be\ninstantiated passing it a host and optional port number. If no port\nnumber is passed, the port is extracted from the host string if it has\nthe form `host:port`, else the default HTTP port (80) is used.\nIf no host is passed, no connection is made, and the `connect`\nmethod should be used to connect to a server. For example, the\nfollowing calls all create instances that connect to the server at the\nsame host and port:\nOnce an `HTTP` instance has been connected to an HTTP server, it\nshould be used as follows:\n- 1. 1. Make exactly one call to the `putrequest()` method.\n2. 2. Make zero or more calls to the `putheader()` method.\n3. 3. Call the `endheaders()` method (this can be omitted if\nstep 4 makes no calls).\n4. 4. Optional calls to the `send()` method.\n5. 5. Call the `getreply()` method.\n6. 6. Call the `getfile()` method and read the data off the\nfile object that it returns.\n## Menu", "python_version": "1.2", "length": 1310, "url": "https://docs.python.org/{python_version}/python-lib/httplib.html"} {"title": "imageop -- Python library reference", "text": "imageop -- Python library reference\nPrev: audioop (audioop.html)\nTop: Top (top.html)\n# 12.2. Built-in Module `imageop`\nThe `imageop` module contains some useful operations on images.\nIt operates on images consisting of 8 or 32 bit pixels\nstored in Python strings. This is the same format as used\nby `gl.lrectwrite` and the `imgfile` module.\nThe module defines the following variables and functions:", "python_version": "1.2", "length": 399, "url": "https://docs.python.org/{python_version}/python-lib/imageop.html"} {"title": "imgfile -- Python library reference", "text": "imgfile -- Python library reference\nPrev: GL and DEVICE (gl_and_device.html)\nTop: Top (top.html)\n# 16.10. Built-in Module `imgfile`\nThe imgfile module allows python programs to access SGI imglib image\nfiles (also known as .rgb files). The module is far from\ncomplete, but is provided anyway since the functionality that there is\nis enough in some cases. Currently, colormap files are not supported.\nThe module defines the following variables and functions:", "python_version": "1.2", "length": 458, "url": "https://docs.python.org/{python_version}/python-lib/imgfile.html"} {"title": "imp -- Python library reference", "text": "imp -- Python library reference\nPrev: marshal (marshal.html)\nTop: Top (top.html)\n# 3.8. Built-in Module `imp`\nThis module provides an interface to the mechanisms used to implement\nthe `import` statement. It defines the following constants and\nfunctions:\nThe following constants with integer values, defined in the module,\nare used to indicate the search result of `imp.find_module`.\n## Menu", "python_version": "1.2", "length": 391, "url": "https://docs.python.org/{python_version}/python-lib/imp.html"} {"title": "Instant Users Manual -- Python library reference", "text": "Instant Users Manual -- Python library reference\nPrev: Profiler Changes (profiler_changes.html)\nTop: Top (top.html)\n# 10.3. Instant Users Manual\nThis section is provided for users that ``don't want to read the\nmanual.'' It provides a very brief overview, and allows a user to\nrapidly perform profiling on an existing application.\nTo profile an application with a main entry point of `foo()', you\nwould add the following to your module:\nThe above action would cause `foo()' to be run, and a series of\ninformative lines (the profile) to be printed. The above approach is\nmost useful when working with the interpreter. If you would like to\nsave the results of a profile into a file for later examination, you\ncan supply a file name as the second argument to the `run()`\nfunction:\nWhen you wish to review the profile, you should use the methods in the\n`pstats` module. Typically you would load the statistics data as\nfollows:\nThe class `Stats` (the above code just created an instance of\nthis class) has a variety of methods for manipulating and printing the\ndata that was just read into `p'. When you ran\n`profile.run()` above, what was printed was the result of three\nmethod calls:\nThe first method removed the extraneous path from all the module\nnames. The second method sorted all the entries according to the\nstandard module/line/name string that is printed (this is to comply\nwith the semantics of the old profiler). The third method printed out\nall the statistics. You might try the following sort calls:\nThe first call will actually sort the list by function name, and the\nsecond call will print out the statistics. The following are some\ninteresting calls to experiment with:\nThis sorts the profile by cumulative time in a function, and then only\nprints the ten most significant lines. If you want to understand what\nalgorithms are taking time, the above line is what you would use.\nIf you were looking to see what functions were looping a lot, and\ntaking a lot of time, you would do:\nto sort according to time spent within each function, and then print\nthe statistics for the top ten functions.\nYou might also try:\nThis will sort all the statistics by file name, and then print out\nstatistics for only the class init methods ('cause they are spelled\nwith `__init__` in them). As one final example, you could try:\nThis line sorts statistics with a primary key of time, and a secondary\nkey of cumulative time, and then prints out some of the statistics.\nTo be specific, the list is first culled down to 50% (re: `.5')\nof its original size, then only lines containing `init` are\nmaintained, and that sub-sub-list is printed.\nIf you wondered what functions called the above functions, you could\nnow (`p' is still sorted according to the last criteria) do:\nand you would get a list of callers for each of the listed functions.\nIf you want more functionality, you're going to have to read the\nmanual, or guess what the following functions do:", "python_version": "1.2", "length": 2942, "url": "https://docs.python.org/{python_version}/python-lib/instant_users_manual.html"} {"title": "Internal Objects -- Python library reference", "text": "Internal Objects -- Python library reference\nPrev: File Objects (file_objects.html)\nTop: Top (top.html)\n### 2.1.7.9. Internal Objects\n(See the Python Reference Manual for these.)", "python_version": "1.2", "length": 178, "url": "https://docs.python.org/{python_version}/python-lib/internal_objects.html"} {"title": "Internet and WWW -- Python library reference", "text": "Internet and WWW -- Python library reference\nPrev: The Python Profiler (the_python_profiler.html)\nTop: Top (top.html)\n# 11. Internet and WWW Services\nThe modules described in this chapter provide various services to\nWorld-Wide Web (WWW) clients and/or services, and a few modules\nrelated to news and email. They are all implemented in Python. Some\nof these modules require the presence of the system-dependent module\n`sockets`, which is currently only fully supported on Unix and\nWindows NT. Here is an overview:\n## Menu", "python_version": "1.2", "length": 523, "url": "https://docs.python.org/{python_version}/python-lib/internet_and_www.html"} {"title": "Introduction -- Python library reference", "text": "Introduction -- Python library reference\nPrev: Top (top.html)\nTop: Top (top.html)\n# 1. Introduction\nThe ``Python library'' contains several different kinds of components.\nIt contains data types that would normally be considered part of the\n``core'' of a language, such as numbers and lists. For these types,\nthe Python language core defines the form of literals and places some\nconstraints on their semantics, but does not fully define the\nsemantics. (On the other hand, the language core does define\nsyntactic properties like the spelling and priorities of operators.)\nThe library also contains built-in functions and exceptions ---\nobjects that can be used by all Python code without the need of an\n`import` statement. Some of these are defined by the core\nlanguage, but many are not essential for the core semantics and are\nonly described here.\nThe bulk of the library, however, consists of a collection of modules.\nThere are many ways to dissect this collection. Some modules are\nwritten in C and built in to the Python interpreter; others are\nwritten in Python and imported in source form. Some modules provide\ninterfaces that are highly specific to Python, like printing a stack\ntrace; some provide interfaces that are specific to particular\noperating systems, like socket I/O; others provide interfaces that are\nspecific to a particular application domain, like the World-Wide Web.\nSome modules are avaiable in all versions and ports of Python; others\nare only available when the underlying system supports or requires\nthem; yet others are available only when a particular configuration\noption was chosen at the time when Python was compiled and installed.\nThis manual is organized ``from the inside out'': it first describes\nthe built-in data types, then the built-in functions and exceptions,\nand finally the modules, grouped in chapters of related modules. The\nordering of the chapters as well as the ordering of the modules within\neach chapter is roughly from most relevant to least important.\nThis means that if you start reading this manual from the start, and\nskip to the next chapter when you get bored, you will get a reasonable\noverview of the available modules and application areas that are\nsupported by the Python library. Of course, you don't have to\nread it like a novel --- you can also browse the table of contents (in\nfront of the manual), or look for a specific function, module or term\nin the index (in the back). And finally, if you enjoy learning about\nrandom subjects, you choose a random page number (see module\n`rand`) and read a section or two.\nLet the show begin!", "python_version": "1.2", "length": 2597, "url": "https://docs.python.org/{python_version}/python-lib/introduction.html"} {"title": "jpeg -- Python library reference", "text": "jpeg -- Python library reference\nPrev: aifc (aifc.html)\nTop: Top (top.html)\n# 12.4. Built-in Module `jpeg`\nThe module `jpeg` provides access to the jpeg compressor and\ndecompressor written by the Independent JPEG Group. JPEG is a (draft?)\nstandard for compressing pictures. For details on jpeg or the\nIndependent JPEG Group software refer to the JPEG standard or the\ndocumentation provided with the software.\nThe `jpeg` module defines these functions:\nCompress and uncompress raise the error `jpeg.error` in case of errors.", "python_version": "1.2", "length": 524, "url": "https://docs.python.org/{python_version}/python-lib/jpeg.html"} {"title": "Limitations -- Python library reference", "text": "Limitations -- Python library reference\nPrev: Reference Manual (reference_manual.html)\nTop: Top (top.html)\n# 10.6. Limitations\nThere are two fundamental limitations on this profiler. The first is\nthat it relies on the Python interpreter to dispatch call,\nreturn, and exception events. Compiled C code does not\nget interpreted, and hence is ``invisible'' to the profiler. All time\nspent in C code (including builtin functions) will be charged to the\nPython function that invoked the C code. If the C code calls out\nto some native Python code, then those calls will be profiled\nproperly.\nThe second limitation has to do with accuracy of timing information.\nThere is a fundamental problem with deterministic profilers involving\naccuracy. The most obvious restriction is that the underlying ``clock''\nis only ticking at a rate (typically) of about .001 seconds. Hence no\nmeasurements will be more accurate that that underlying clock. If\nenough measurements are taken, then the ``error'' will tend to average\nout. Unfortunately, removing this first error induces a second source\nof error...\nThe second problem is that it ``takes a while'' from when an event is\ndispatched until the profiler's call to get the time actually\ngets the state of the clock. Similarly, there is a certain lag\nwhen exiting the profiler event handler from the time that the clock's\nvalue was obtained (and then squirreled away), until the user's code\nis once again executing. As a result, functions that are called many\ntimes, or call many functions, will typically accumulate this error.\nThe error that accumulates in this fashion is typically less than the\naccuracy of the clock (i.e., less than one clock tick), but it\ncan accumulate and become very significant. This profiler\nprovides a means of calibrating itself for a given platform so that\nthis error can be probabilistically (i.e., on the average) removed.\nAfter the profiler is calibrated, it will be more accurate (in a least\nsquare sense), but it will sometimes produce negative numbers (when\ncall counts are exceptionally low, and the gods of probability work\nagainst you :-). ) Do NOT be alarmed by negative numbers in\nthe profile. They should only appear if you have calibrated\nyour profiler, and the results are actually better than without\ncalibration.", "python_version": "1.2", "length": 2293, "url": "https://docs.python.org/{python_version}/python-lib/limitations.html"} {"title": "mac -- Python library reference", "text": "mac -- Python library reference\nPrev: Macintosh Specific Services (macintosh_specific_services.html)\nTop: Top (top.html)\n# 14.1. Built-in Module `mac`\nThis module provides a subset of the operating system dependent\nfunctionality provided by the optional built-in module `posix`.\nIt is best accessed through the more portable standard module\n`os`.\nThe following functions are available in this module:\n`chdir`,\n`getcwd`,\n`listdir`,\n`mkdir`,\n`rename`,\n`rmdir`,\n`stat`,\n`sync`,\n`unlink`,\nas well as the exception `error`.", "python_version": "1.2", "length": 518, "url": "https://docs.python.org/{python_version}/python-lib/mac.html"} {"title": "macconsole -- Python library reference", "text": "macconsole -- Python library reference\nPrev: ctb (ctb.html)\nTop: Top (top.html)\n# 14.4. Built-in Module `macconsole`\nThis module is available on the Macintosh, provided Python has been\nbuilt using the Think C compiler. It provides an interface to the\nThink console package, with which basic text windows can be created.\n## Menu", "python_version": "1.2", "length": 327, "url": "https://docs.python.org/{python_version}/python-lib/macconsole.html"} {"title": "macconsole options object -- Python library reference", "text": "macconsole options object -- Python library reference\nPrev: macconsole (macconsole.html)\nTop: Top (top.html)\n## 14.4.1. macconsole options object\nThese options are examined when a window is created:", "python_version": "1.2", "length": 198, "url": "https://docs.python.org/{python_version}/python-lib/macconsole_options_object.html"} {"title": "macdnr -- Python library reference", "text": "macdnr -- Python library reference\nPrev: macconsole (macconsole.html)\nTop: Top (top.html)\n# 14.5. Built-in Module `macdnr`\nThis module provides an interface to the Macintosh Domain Name\nResolver. It is usually used in conjunction with the mactcp\nmodule, to map hostnames to IP-addresses. It may not be available in\nall Mac Python versions.\nThe `macdnr` module defines the following functions:\n## Menu", "python_version": "1.2", "length": 402, "url": "https://docs.python.org/{python_version}/python-lib/macdnr.html"} {"title": "macfs -- Python library reference", "text": "macfs -- Python library reference\nPrev: macdnr (macdnr.html)\nTop: Top (top.html)\n# 14.6. Built-in Module `macfs`\nThis module provides access to macintosh FSSpec handling, the Alias\nManager, finder aliases and the Standard File package.\nWhenever a function or method expects a file argument, this\nargument can be one of three things: (1) a full or partial Macintosh\npathname, (2) an FSSpec object or (3) a 3-tuple `(wdRefNum,\nparID, name)` as described in Inside Mac VI.\nand the standard file package can also be found there.\n## Menu", "python_version": "1.2", "length": 532, "url": "https://docs.python.org/{python_version}/python-lib/macfs.html"} {"title": "Macintosh Specific Services -- Python library reference", "text": "Macintosh Specific Services -- Python library reference\nPrev: Cryptographic Services (cryptographic_services.html)\nTop: Top (top.html)\n# 14. Macintosh Specific Services\nThe modules in this chapter are available on the Apple Macintosh only.\n## Menu", "python_version": "1.2", "length": 247, "url": "https://docs.python.org/{python_version}/python-lib/macintosh_specific_services.html"} {"title": "macpath -- Python library reference", "text": "macpath -- Python library reference\nPrev: mac (mac.html)\nTop: Top (top.html)\n# 14.2. Standard Module `macpath`\nThis module provides a subset of the pathname manipulation functions\navailable from the optional standard module `posixpath`. It is\nbest accessed through the more portable standard module `os`, as\n`os.path`.\nThe following functions are available in this module:\n`normcase`,\n`isabs`,\n`join`,\n`split`,\n`isdir`,\n`isfile`,\n`exists`.", "python_version": "1.2", "length": 440, "url": "https://docs.python.org/{python_version}/python-lib/macpath.html"} {"title": "macspeech -- Python library reference", "text": "macspeech -- Python library reference\nPrev: mactcp (mactcp.html)\nTop: Top (top.html)\n# 14.8. Built-in Module `macspeech`\nThis module provides an interface to the Macintosh Speech Manager,\nallowing you to let the Macintosh utter phrases. You need a version of\nthe speech manager extension (version 1 and 2 have been tested) in\nyour `Extensions` folder for this to work. The module does not\nprovide full access to all features of the Speech Manager yet. It may\nnot be available in all Mac Python versions.\n## Menu", "python_version": "1.2", "length": 512, "url": "https://docs.python.org/{python_version}/python-lib/macspeech.html"} {"title": "mactcp -- Python library reference", "text": "mactcp -- Python library reference\nPrev: macfs (macfs.html)\nTop: Top (top.html)\n# 14.7. Built-in Module `mactcp`\nThis module provides an interface to the Macintosh TCP/IP driver\nMacTCP.`macdnr` which provides an\ninterface to the name-server (allowing you to translate hostnames to\nip-addresses), a module `MACTCP` which has symbolic names for\nconstants constants used by MacTCP and a wrapper module `socket`\nwhich mimics the UNIX socket interface (as far as possible). It may\nnot be available in all Mac Python versions.\nA complete description of the MacTCP interface can be found in the\nApple MacTCP API documentation.\n## Menu", "python_version": "1.2", "length": 628, "url": "https://docs.python.org/{python_version}/python-lib/mactcp.html"} {"title": "Mapping Types -- Python library reference", "text": "Mapping Types -- Python library reference\nPrev: Sequence Types (sequence_types.html)\nTop: Top (top.html)\n## 2.1.6. Mapping Types\nA mapping object maps values of one type (the key type) to\narbitrary objects. Mappings are mutable objects. There is currently\nonly one standard mapping type, the dictionary. A dictionary's keys are\nalmost arbitrary values. The only types of values not acceptable as\nkeys are values containing lists or dictionaries or other mutable\ntypes that are compared by value rather than by object identity.\nNumeric types used for keys obey the normal rules for numeric\ncomparison: if two numbers compare equal (e.g. 1 and 1.0) then they\ncan be used interchangeably to index the same dictionary entry.\nDictionaries are created by placing a comma-separated list of\n`key :,varvalue` pairs within braces, for example:\n`{'jack':,4098, 'sjoerd':,4127}` or\n`{4098:,'jack', 4127:,'sjoerd'}`.\nThe following operations are defined on mappings (where a is a\nmapping, k is a key and x is an arbitrary object):\nNotes:", "python_version": "1.2", "length": 1028, "url": "https://docs.python.org/{python_version}/python-lib/mapping_types.html"} {"title": "marshal -- Python library reference", "text": "marshal -- Python library reference\nPrev: copy (copy.html)\nTop: Top (top.html)\n# 3.7. Built-in Module `marshal`\nThis module contains functions that can read and write Python\nvalues in a binary format. The format is specific to Python, but\nindependent of machine architecture issues (e.g., you can write a\nPython value to a file on a PC, transport the file to a Sun, and read\nit back there). Details of the format are undocumented on purpose;\nit may change between Python versions (although it rarely does).(1) (#footnotetext1)\nThis is not a general ``persistency'' module. For general persistency\nand transfer of Python objects through RPC calls, see the modules\n`pickle` and `shelve`. The `marshal` module exists\nmainly to support reading and writing the ``pseudo-compiled'' code for\nPython modules of `.pyc' files.\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can\nbe written and read by this module. The following types are supported:\n`None`, integers, long integers, floating point numbers,\nstrings, tuples, lists, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\nCaveat: On machines where C's `long int` type has more than\n32 bits (such as the DEC Alpha or the HP Precision Architecture), it\nis possible to create plain Python integers that are longer than 32\nbits. Since the current `marshal` module uses 32 bits to\ntransfer plain Python integers, such values are silently truncated.\nThis particularly affects the use of very long integer literals in\nPython modules --- these will be accepted by the parser on such\nmachines, but will be silently be truncated when the module is read\nfrom the `.pyc` instead.(2) (#footnotetext2)\nThere are functions that read/write files as well as functions\noperating on strings.\nThe module defines these functions:\n## ---------- Footnotes ----------\n(1) (#footnoteref1)\nThe name of this module stems from a bit of terminology used\nby the designers of Modula-3 (amongst others), who use the term\n``marshalling'' for shipping of data around in a self-contained form.\nStrictly speaking, ``to marshal'' means to convert some data from\ninternal to external form (in an RPC buffer for instance) and\n``unmarshalling'' for the reverse process.\n(2) (#footnoteref2)\nA solution would be to refuse such literals in the parser,\nsince they are inherently non-portable. Another solution would be to\nlet the `marshal` module raise an exception when an integer value\nwould be truncated. At least one of these solutions will be\nimplemented in a future version.", "python_version": "1.2", "length": 2799, "url": "https://docs.python.org/{python_version}/python-lib/marshal.html"} {"title": "math -- Python library reference", "text": "math -- Python library reference\nPrev: Miscellaneous Services (miscellaneous_services.html)\nTop: Top (top.html)\n# 5.1. Built-in Module `math`\nThis module is always available.\nIt provides access to the mathematical functions defined by the C\nstandard.\nThey are:\nNote that `frexp` and `modf` have a different call/return\npattern than their C equivalents: they take a single argument and\nreturn a pair of values, rather than returning their second return\nvalue through an `output parameter' (there is no such thing in Python).\nThe `hypot` function, which is not standard C, is not available\non all platforms.\nThe module also defines two mathematical constants:", "python_version": "1.2", "length": 657, "url": "https://docs.python.org/{python_version}/python-lib/math.html"} {"title": "md5 -- Python library reference", "text": "md5 -- Python library reference\nPrev: Cryptographic Services (cryptographic_services.html)\nTop: Top (top.html)\n# 13.1. Built-in Module `md5`\nThis module implements the interface to RSA's MD5 message digest\nalgorithm (see also Internet RFC 1321). Its use is quite\nstraightforward: use the `md5.new()` to create an md5 object.\nYou can now feed this object with arbitrary strings using the\n`update()` method, and at any point you can ask it for the\ndigest (a strong kind of 128-bit checksum,\na.k.a. ``fingerprint'') of the contatenation of the strings fed to it\nso far using the `digest()` method.\nFor example, to obtain the digest of the string `\"Nobody inspects\nthe spammish repetition\"`:\nMore condensed:\nAn md5 object has the following methods:", "python_version": "1.2", "length": 745, "url": "https://docs.python.org/{python_version}/python-lib/md5.html"} {"title": "Menu Objects -- Python library reference", "text": "Menu Objects -- Python library reference\nPrev: Drawing Objects (drawing_objects.html)\nTop: Top (top.html)\n## 15.1.4. Menu Objects\nA menu object represents a menu.\nThe menu is destroyed when the menu object is deleted.\nThe following methods are defined:", "python_version": "1.2", "length": 252, "url": "https://docs.python.org/{python_version}/python-lib/menu_objects.html"} {"title": "Message Objects -- Python library reference", "text": "Message Objects -- Python library reference\nPrev: rfc822 (rfc822.html)\nTop: Top (top.html)\n## 11.10.1. Message Objects\nA `Message` instance has the following methods:\n`Message` instances also support a read-only mapping interface.\nIn particular: `m[name]` is the same as `m.getheader(name)`;\nand `len(m)`, `m.has_key(name)`, `m.keys()`,\n`m.values()` and `m.items()` act as expected (and\nconsistently).\nFinally, `Message` instances have two public instance variables:", "python_version": "1.2", "length": 466, "url": "https://docs.python.org/{python_version}/python-lib/message_objects.html"} {"title": "Methods -- Python library reference", "text": "Methods -- Python library reference\nPrev: Functions (functions.html)\nTop: Top (top.html)\n### 2.1.7.4. Methods\nMethods are functions that are called using the attribute notation.\nThere are two flavors: built-in methods (such as `append()` on\nlists) and class instance methods. Built-in methods are described\nwith the types that support them.\nThe implementation adds two special read-only attributes to class\ninstance methods: `m .im_self` is the object whose method this\nis, and `m .im_func` is the function implementing the method.\nCalling `m ( arg-1 , arg-2 , ... , arg-n )` is completely equivalent to calling\n`m .im_func( m .im_self, arg-1 , arg-2 , ... , arg-n )`.\n(See the Python Reference Manual for more info.)", "python_version": "1.2", "length": 718, "url": "https://docs.python.org/{python_version}/python-lib/methods.html"} {"title": "mimetools -- Python library reference", "text": "mimetools -- Python library reference\nPrev: rfc822 (rfc822.html)\nTop: Top (top.html)\n# 11.11. Standard Module `mimetools`\nThis module defines a subclass of the class `rfc822.Message` and\na number of utility functions that are useful for the manipulation for\nMIME style multipart or encoded message.\nIt defines the following items:\n## Menu", "python_version": "1.2", "length": 338, "url": "https://docs.python.org/{python_version}/python-lib/mimetools.html"} {"title": "mimetools.Message Methods -- Python library reference", "text": "mimetools.Message Methods -- Python library reference\nPrev: mimetools (mimetools.html)\nTop: Top (top.html)\n## 11.11.1. Additional Methods of Message objects\nThe `mimetools.Message` class defines the following methods in\naddition to the `rfc822.Message` class:", "python_version": "1.2", "length": 259, "url": "https://docs.python.org/{python_version}/python-lib/mimetools.message_methods.html"} {"title": "Miscellaneous Services -- Python library reference", "text": "Miscellaneous Services -- Python library reference\nPrev: String Services (string_services.html)\nTop: Top (top.html)\n# 5. Miscellaneous Services\nThe modules described in this chapter provide miscellaneous services\nthat are available in all Python versions. Here's an overview:\n## Menu", "python_version": "1.2", "length": 284, "url": "https://docs.python.org/{python_version}/python-lib/miscellaneous_services.html"} {"title": "Module Index -- Python library reference", "text": "Module Index -- Python library reference\nPrev: Variable Index (variable_index.html)\nTop: Top (top.html)\n# Module Index", "python_version": "1.2", "length": 118, "url": "https://docs.python.org/{python_version}/python-lib/module_index.html"} {"title": "Modules -- Python library reference", "text": "Modules -- Python library reference\nPrev: Other Built-in Types (other_built-in_types.html)\nTop: Top (top.html)\n### 2.1.7.1. Modules\nThe only special operation on a module is attribute access:\n`m . name`, where m is a module and name accesses\na name defined in m's symbol table. Module attributes can be\nassigned to. (Note that the `import` statement is not, strictly\nspoken, an operation on a module object; `import foo` does not\nrequire a module object named foo to exist, rather it requires\nan (external) definition for a module named foo\nsomewhere.)\nA special member of every module is `__dict__`.\nThis is the dictionary containing the module's symbol table.\nModifying this dictionary will actually change the module's symbol\ntable, but direct assignment to the `__dict__` attribute is not\npossible (i.e., you can write `m .__dict__['a'] = 1`, which\ndefines `m .a` to be `1`, but you can't write `m .__dict__ = {}`.\nModules are written like this: ``.", "python_version": "1.2", "length": 969, "url": "https://docs.python.org/{python_version}/python-lib/modules.html"} {"title": "More String Operations -- Python library reference", "text": "More String Operations -- Python library reference\nPrev: Sequence Types (sequence_types.html)\nTop: Top (top.html)\n### 2.1.5.1. More String Operations\nString objects have one unique built-in operation: the `%`\noperator (modulo) with a string left argument interprets this string\nas a C sprintf format string to be applied to the right argument, and\nreturns the string resulting from this formatting operation.\nThe right argument should be a tuple with one item for each argument\nrequired by the format string; if the string requires a single\nargument, the right argument may also be a single non-tuple object.(1) (#footnotetext1)\nThe following format characters are understood:\n%, c, s, i, d, u, o, x, X, e, E, f, g, G.\nWidth and precision may be a * to specify that an integer argument\nspecifies the actual width or precision. The flag characters -, +,\nblank, # and 0 are understood. The size specifiers h, l or L may be\npresent but are ignored. The `%s` conversion takes any Python\nobject and converts it to a string using `str()` before\nformatting it. The ANSI features `%p` and `%n`\nare not supported. Since Python strings have an explicit length,\n`%s` conversions don't assume that `'\\0'` is the end of\nthe string.\nFor safety reasons, floating point precisions are clipped to 50;\n`%f` conversions for numbers whose absolute value is over 1e25\nare replaced by `%g` conversions.(2) (#footnotetext2)\nAll other errors raise exceptions.\nIf the right argument is a dictionary (or any kind of mapping), then\nthe formats in the string must have a parenthesized key into that\ndictionary inserted immediately after the `%` character, and\neach format formats the corresponding entry from the mapping. E.g.\nIn this case no * specifiers may occur in a format (since they a\nrequire sequential parameter list).\nAdditional string operations are defined in standard module\n`string` and in built-in module `regex`.\n## ---------- Footnotes ----------\n(1) (#footnoteref1)\nA tuple object in this case should be a singleton.\n(2) (#footnoteref2)\nThese numbers are fairly arbitrary. They are intended to\navoid printing endless strings of meaningless digits without hampering\ncorrect use and without having to know the exact precision of floating\npoint values on a particular machine.", "python_version": "1.2", "length": 2263, "url": "https://docs.python.org/{python_version}/python-lib/more_string_operations.html"} {"title": "mpz -- Python library reference", "text": "mpz -- Python library reference\nPrev: md5 (md5.html)\nTop: Top (top.html)\n# 13.2. Built-in Module `mpz`\nThis module implements the interface to part of the GNU MP library.\nThis library contains arbitrary precision integer and rational number\narithmetic routines. Only the interfaces to the integer\n(`mpz_...') routines are provided. If not stated\notherwise, the description in the GNU MP documentation can be applied.\nIn general, mpz-numbers can be used just like other standard\nPython numbers, e.g. you can use the built-in operators like `+`,\n`*`, etc., as well as the standard built-in functions like\n`abs`, `int`, ..., `divmod`, `pow`.\nPlease note: the bitwise-xor operation has been implemented as\na bunch of ands, inverts and ors, because the library\nlacks an `mpz_xor` function, and I didn't need one.\nYou create an mpz-number by calling the function called `mpz` (see\nbelow for an exact description). An mpz-number is printed like this:\n`mpz( value )`.\nA number of extra functions are defined in this module. Non\nmpz-arguments are converted to mpz-values first, and the functions\nreturn mpz-numbers.\nAn mpz-number has one method:", "python_version": "1.2", "length": 1136, "url": "https://docs.python.org/{python_version}/python-lib/mpz.html"} {"title": "Multimedia Services -- Python library reference", "text": "Multimedia Services -- Python library reference\nPrev: Internet and WWW (internet_and_www.html)\nTop: Top (top.html)\n# 12. Multimedia Services\nThe modules described in this chapter implement various algorithms or\ninterfaces that are mainly useful for multimedia applications. They\nare available at the discretion of the installation. Here's an overview:\n## Menu", "python_version": "1.2", "length": 361, "url": "https://docs.python.org/{python_version}/python-lib/multimedia_services.html"} {"title": "Mutable Sequence Types -- Python library reference", "text": "Mutable Sequence Types -- Python library reference\nPrev: More String Operations (more_string_operations.html)\nTop: Top (top.html)\n### 2.1.5.2. Mutable Sequence Types\nList objects support additional operations that allow in-place\nmodification of the object.\nThese operations would be supported by other mutable sequence types\n(when added to the language) as well.\nStrings and tuples are immutable sequence types and such objects cannot\nbe modified once created.\nThe following operations are defined on mutable sequence types (where\nx is an arbitrary object):\n Notes:", "python_version": "1.2", "length": 565, "url": "https://docs.python.org/{python_version}/python-lib/mutable_sequence_types.html"} {"title": "NNTP Objects -- Python library reference", "text": "NNTP Objects -- Python library reference\nPrev: nntplib (nntplib.html)\nTop: Top (top.html)\n## 11.6.1. NNTP Objects\nNNTP instances have the following methods. The response that is\nreturned as the first item in the return tuple of almost all methods\nis the server's response: a string beginning with a three-digit code.\nIf the server's response indicates an error, the method raises one of\nthe above exceptions.", "python_version": "1.2", "length": 409, "url": "https://docs.python.org/{python_version}/python-lib/nntp_objects.html"} {"title": "nntplib -- Python library reference", "text": "nntplib -- Python library reference\nPrev: gopherlib (gopherlib.html)\nTop: Top (top.html)\n# 11.6. Standard Module `nntplib`\nThis module defines the class `NNTP` which implements the client\nside of the NNTP protocol. It can be used to implement a news reader\nor poster, or automated news processors. For more information on NNTP\n(Network News Transfer Protocol), see Internet RFC 977.\nHere are two small examples of how it can be used. To list some\nstatistics about a newsgroup and print the subjects of the last 10\narticles:\n@small{\n}\nTo post an article from a file (this assumes that the article has\nvalid headers):\nThe module itself defines the following items:\n## Menu", "python_version": "1.2", "length": 672, "url": "https://docs.python.org/{python_version}/python-lib/nntplib.html"} {"title": "Numeric Types -- Python library reference", "text": "Numeric Types -- Python library reference\nPrev: Comparisons (comparisons.html)\nTop: Top (top.html)\n## 2.1.4. Numeric Types\nThere are three numeric types: plain integers, long integers, and\nfloating point numbers. Plain integers (also just called integers)\nare implemented using `long` in C, which gives them at least 32\nbits of precision. Long integers have unlimited precision. Floating\npoint numbers are implemented using `double` in C. All bets on\ntheir precision are off unless you happen to know the machine you are\nworking with.\nNumbers are created by numeric literals or as the result of built-in\nfunctions and operators. Unadorned integer literals (including hex\nand octal numbers) yield plain integers. Integer literals with an `L'\nor `l' suffix yield long integers\n(`L' is preferred because `1l` looks too much like eleven!).\nNumeric literals containing a decimal point or an exponent sign yield\nfloating point numbers.\nPython fully supports mixed arithmetic: when a binary arithmetic\noperator has operands of different numeric types, the operand with the\n``smaller'' type is converted to that of the other, where plain\ninteger is smaller than long integer is smaller than floating point.\nComparisons between numbers of mixed type use the same rule.(1) (#footnotetext1)\nThe functions `int()`, `long()` and `float()` can be used\nto coerce numbers to a specific type.\nAll numeric types support the following operations, sorted by\nascending priority (operations in the same box have the same\npriority; all numeric operations have a higher priority than\ncomparison operations):\nNotes:\n## Menu\n## ---------- Footnotes ----------\n(1) (#footnoteref1)\nAs a consequence, the list `[1, 2]` is considered equal\nto `[1.0, 2.0]`, and similar for tuples.", "python_version": "1.2", "length": 1756, "url": "https://docs.python.org/{python_version}/python-lib/numeric_types.html"} {"title": "OldProfile Class -- Python library reference", "text": "OldProfile Class -- Python library reference\nPrev: Profiler Extensions (profiler_extensions.html)\nTop: Top (top.html)\n## 10.8.1. OldProfile Class\nThe following derived profiler simulates the old style profiler,\nproviding errant results on recursive functions. The reason for the\nusefulness of this profiler is that it runs faster (i.e., less\noverhead) than the old profiler. It still creates all the caller\nstats, and is quite useful when there is no recursion in the\nuser's code. It is also a lot more accurate than the old profiler, as\nit does not charge all its overhead time to the user's code.", "python_version": "1.2", "length": 600, "url": "https://docs.python.org/{python_version}/python-lib/oldprofile_class.html"} {"title": "Optional Operating System Services -- Python library reference", "text": "Optional Operating System Services -- Python library reference\nPrev: Generic Operating System Services (generic_operating_system_services.html)\nTop: Top (top.html)\n# 7. Optional Operating System Services\nThe modules described in this chapter provide interfaces to operating\nsystem features that are available on selected operating systems only.\nThe interfaces are generally modelled after the UNIX or C\ninterfaces but they are available on some other systems as well\n(e.g. Windows or NT). Here's an overview:\n## Menu", "python_version": "1.2", "length": 517, "url": "https://docs.python.org/{python_version}/python-lib/optional_operating_system_services.html"} {"title": "os -- Python library reference", "text": "os -- Python library reference\nPrev: Generic Operating System Services (generic_operating_system_services.html)\nTop: Top (top.html)\n# 6.1. Standard Module `os`\nThis module provides a more portable way of using operating system\n(OS) dependent functionality than importing an OS dependent built-in\nmodule like `posix`.\nWhen the optional built-in module `posix` is available, this\nmodule exports the same functions and data as `posix`; otherwise,\nit searches for an OS dependent built-in module like `mac` and\nexports the same functions and data as found there. The design of all\nPython's built-in OS dependent modules is such that as long as the same\nfunctionality is available, it uses the same interface; e.g., the\nfunction `os.stat( file )` returns stat info about a file in a\nformat compatible with the POSIX interface.\nExtensions peculiar to a particular OS are also available through the\n`os` module, but using them is of course a threat to portability!\nNote that after the first time `os` is imported, there is no\nperformance penalty in using functions from `os` instead of\ndirectly from the OS dependent built-in module, so there should be\nno reason not to use `os`!\nIn addition to whatever the correct OS dependent module exports, the\nfollowing variables and functions are always exported by `os`:\n(The functions `os.execv()` and `execve()` are not\ndocumented here, since they are implemented by the OS dependent\nmodule. If the OS dependent module doesn't define either of these,\nthe functions that rely on it will raise an exception. They are\ndocumented in the section on module `posix`, together with all\nother functions that `os` imports from the OS dependent module.)", "python_version": "1.2", "length": 1678, "url": "https://docs.python.org/{python_version}/python-lib/os.html"} {"title": "Other Built-in Types -- Python library reference", "text": "Other Built-in Types -- Python library reference\nPrev: Mapping Types (mapping_types.html)\nTop: Top (top.html)\n## 2.1.7. Other Built-in Types\nThe interpreter supports several other kinds of objects.\nMost of these support only one or two operations.\n## Menu", "python_version": "1.2", "length": 255, "url": "https://docs.python.org/{python_version}/python-lib/other_built-in_types.html"} {"title": "pickle -- Python library reference", "text": "pickle -- Python library reference\nPrev: traceback (traceback.html)\nTop: Top (top.html)\n# 3.4. Standard Module `pickle`\nThe `pickle` module implements a basic but powerful algorithm for\n``pickling'' (a.k.a. serializing, marshalling or flattening) nearly\narbitrary Python objects. This is the act of converting objects to a\nstream of bytes (and back: ``unpickling'').\nThis is a more primitive notion than\npersistency --- although `pickle` reads and writes file objects,\nit does not handle the issue of naming persistent objects, nor the\n(even more complicated) area of concurrent access to persistent\nobjects. The `pickle` module can transform a complex object into\na byte stream and it can transform the byte stream into an object with\nthe same internal structure. The most obvious thing to do with these\nbyte streams is to write them onto a file, but it is also conceivable\nto send them across a network or store them in a database. The module\n`shelve` provides a simple interface to pickle and unpickle\nobjects on ``dbm''-style database files.\nUnlike the built-in module `marshal`, `pickle` handles the\nfollowing correctly:\n- • recursive objects (objects containing references to themselves)\n • object sharing (references to the same object in different places)\n • user-defined classes and their instances\nThe data format used by `pickle` is Python-specific. This has\nthe advantage that there are no restrictions imposed by external\nstandards such as CORBA (which probably can't represent pointer\nsharing or recursive objects); however it means that non-Python\nprograms may not be able to reconstruct pickled Python objects.\nThe `pickle` data format uses a printable ASCII representation.\nThis is slightly more voluminous than a binary representation.\nHowever, small integers actually take less space when\nrepresented as minimal-size decimal strings than when represented as\n32-bit binary numbers, and strings are only much longer if they\ncontain many control characters or 8-bit characters. The big\nadvantage of using printable ASCII (and of some other characteristics\nof `pickle`'s representation) is that for debugging or recovery\npurposes it is possible for a human to read the pickled file with a\nstandard text editor. (I could have gone a step further and used a\nnotation like S-expressions, but the parser\n(currently written in Python) would have been\nconsiderably more complicated and slower, and the files would probably\nhave become much larger.)\nThe `pickle` module doesn't handle code objects, which the\n`marshal` module does. I suppose `pickle` could, and maybe\nit should, but there's probably no great need for it right now (as\nlong as `marshal` continues to be used for reading and writing\ncode objects), and at least this avoids the possibility of smuggling\nTrojan horses into a program.\nFor the benefit of persistency modules written using `pickle`, it\nsupports the notion of a reference to an object outside the pickled\ndata stream. Such objects are referenced by a name, which is an\narbitrary string of printable ASCII characters. The resolution of\nsuch names is not defined by the `pickle` module --- the\npersistent object module will have to implement a method\n`persistent_load`. To write references to persistent objects,\nthe persistent module must define a method `persistent_id` which\nreturns either `None` or the persistent ID of the object.\nThere are some restrictions on the pickling of class instances.\nFirst of all, the class must be defined at the top level in a module.\nNext, it must normally be possible to create class instances by\ncalling the class without arguments. If this is undesirable, the\nclass can define a method `__getinitargs__()`, which should\nreturn a tuple containing the arguments to be passed to the\nclass constructor (`__init__()`).\nClasses can further influence how their instances are pickled --- if the class\ndefines the method `__getstate__()`, it is called and the return\nstate is pickled as the contents for the instance, and if the class\ndefines the method `__setstate__()`, it is called with the\nunpickled state. (Note that these methods can also be used to\nimplement copying class instances.) If there is no\n`__getstate__()` method, the instance's `__dict__` is\npickled. If there is no `__setstate__()` method, the pickled\nobject must be a dictionary and its items are assigned to the new\ninstance's dictionary. (If a class defines both `__getstate__()`\nand `__setstate__()`, the state object needn't be a dictionary\n--- these methods can do what they want.) This protocol is also used\nby the shallow and deep copying operations defined in the `copy`\nmodule.\nNote that when class instances are pickled, their class's code and\ndata are not pickled along with them. Only the instance data are\npickled. This is done on purpose, so you can fix bugs in a class or\nadd methods and still load objects that were created with an earlier\nversion of the class. If you plan to have long-lived objects that\nwill see many versions of a class, it may be worthwhile to put a version\nnumber in the objects so that suitable conversions can be made by the\nclass's `__setstate__()` method.\nWhen a class itself is pickled, only its name is pickled --- the class\ndefinition is not pickled, but re-imported by the unpickling process.\nTherefore, the restriction that the class must be defined at the top\nlevel in a module applies to pickled classes as well.\nThe interface can be summarized as follows.\nTo pickle an object `x` onto a file `f`, open for writing:\nA shorthand for this is:\nTo unpickle an object `x` from a file `f`, open for reading:\nA shorthand is:\nThe `Pickler` class only calls the method `f.write` with a\nstring argument. The `Unpickler` calls the methods `f.read`\n(with an integer argument) and `f.readline` (without argument),\nboth returning a string. It is explicitly allowed to pass non-file\nobjects here, as long as they have the right methods.\nThe following types can be pickled:\n- • `None`\n• integers, long integers, floating point numbers\n• strings\n• tuples, lists and dictionaries containing only picklable objects\n• classes that are defined at the top level in a module\n• instances of such classes whose `__dict__` or\n`__setstate__()` is picklable\nAttempts to pickle unpicklable objects will raise the\n`PicklingError` exception; when this happens, an unspecified\nnumber of bytes may have been written to the file.\nIt is possible to make multiple calls to the `dump()` method of\nthe same `Pickler` instance. These must then be matched to the\nsame number of calls to the `load()` instance of the\ncorresponding `Unpickler` instance. If the same object is\npickled by multiple `dump()` calls, the `load()` will all\nyield references to the same object. Warning: this is intended\nfor pickling multiple objects without intervening modifications to the\nobjects or their parts. If you modify an object and then pickle it\nagain using the same `Pickler` instance, the object is not\npickled again --- a reference to it is pickled and the\n`Unpickler` will return the old value, not the modified one.\n(There are two problems here: (a) detecting changes, and (b)\nmarshalling a minimal set of changes. I have no answers. Garbage\nCollection may also become a problem here.)\nApart from the `Pickler` and `Unpickler` classes, the\nmodule defines the following functions, and an exception:", "python_version": "1.2", "length": 7338, "url": "https://docs.python.org/{python_version}/python-lib/pickle.html"} {"title": "Port Objects -- Python library reference", "text": "Port Objects -- Python library reference\nPrev: Configuration Objects (configuration_objects.html)\nTop: Top (top.html)\n## 16.1.2. Port Objects\nPort objects (returned by `al.openport()` have the following\nmethods:", "python_version": "1.2", "length": 211, "url": "https://docs.python.org/{python_version}/python-lib/port_objects.html"} {"title": "posix -- Python library reference", "text": "posix -- Python library reference\nPrev: UNIX Specific Services (unix_specific_services.html)\nTop: Top (top.html)\n# 8.1. Built-in Module `posix`\nThis module provides access to operating system functionality that is\nstandardized by the C Standard and the POSIX standard (a thinly disguised\nUNIX interface).\nDo not import this module directly. Instead, import the\nmodule `os`, which provides a portable version of this\ninterface. On UNIX, the `os` module provides a superset of\nthe `posix` interface. On non-UNIX operating systems the\n`posix` module is not available, but a subset is always available\nthrough the `os` interface. Once `os` is imported, there is\nno performance penalty in using it instead of\n`posix`.\nThe descriptions below are very terse; refer to the\ncorresponding UNIX manual entry for more information. Arguments\ncalled path refer to a pathname given as a string.\nErrors are reported as exceptions; the usual exceptions are given\nfor type errors, while errors reported by the system calls raise\n`posix.error`, described below.\nModule `posix` defines the following data items:\nIt defines the following functions and constants:\n## ---------- Footnotes ----------\n(1) (#footnoteref1)\nThe problem with automatically passing on `environ` is\nthat there is no portable way of changing the environment.", "python_version": "1.2", "length": 1310, "url": "https://docs.python.org/{python_version}/python-lib/posix.html"} {"title": "posixfile -- Python library reference", "text": "posixfile -- Python library reference\nPrev: fcntl (fcntl.html)\nTop: Top (top.html)\n# 8.10. Standard Module `posixfile`\nThis module implements some additional functionality over the built-in\nfile objects. In particular, it implements file locking, control over\nthe file flags, and an easy interface to duplicate the file object.\nThe module defines a new file object, the posixfile object. It\nhas all the standard file object methods and adds the methods\ndescribed below. This module only works for certain flavors of\nUNIX, since it uses `fcntl()` for file locking.\nTo instantiate a posixfile object, use the `open()` function in\nthe posixfile module. The resulting object looks and feels roughly\nthe same as a standard file object.\nThe posixfile module defines the following constants:\nThe posixfile module defines the following functions:\nThe posixfile object defines the following additional methods:\nAll methods return `IOError` when the request fails.\nFormat characters for the `lock()` method have the following meaning:\nIn addition the following modifiers can be added to the format:\nNote:\n(1) The lock returned is in the format `(mode, len, start,\nwhence, pid)` where mode is a character representing the type of lock\n('r' or 'w'). This modifier prevents a request from being granted; it\nis for query purposes only.\nFormat character for the `flags()` method have the following meaning:\nIn addition the following modifiers can be added to the format:\nNote:\n(1) The `!` and `=` modifiers are mutually exclusive.\n(2) This string represents the flags after they may have been altered\nby the same call.\nExamples:", "python_version": "1.2", "length": 1616, "url": "https://docs.python.org/{python_version}/python-lib/posixfile.html"} {"title": "posixpath -- Python library reference", "text": "posixpath -- Python library reference\nPrev: posix (posix.html)\nTop: Top (top.html)\n# 8.2. Standard Module `posixpath`\nThis module implements some useful functions on POSIX pathnames.\nDo not import this module directly. Instead, import the\nmodule `os` and use `os.path`.", "python_version": "1.2", "length": 269, "url": "https://docs.python.org/{python_version}/python-lib/posixpath.html"} {"title": "Profiler Changes -- Python library reference", "text": "Profiler Changes -- Python library reference\nPrev: Profiler Introduction (profiler_introduction.html)\nTop: Top (top.html)\n# 10.2. How Is This Profiler Different From The Old Profiler?\nThe big changes from old profiling module are that you get more\ninformation, and you pay less CPU time. It's not a trade-off, it's a\ntrade-up.\nTo be specific:", "python_version": "1.2", "length": 343, "url": "https://docs.python.org/{python_version}/python-lib/profiler_changes.html"} {"title": "Profiler Extensions -- Python library reference", "text": "Profiler Extensions -- Python library reference\nPrev: Calibration (calibration.html)\nTop: Top (top.html)\n# 10.8. Extensions --- Deriving Better Profilers\nThe `Profile` class of module `profile` was written so that\nderived classes could be developed to extend the profiler. Rather\nthan describing all the details of such an effort, I'll just present\nthe following two examples of derived classes that can be used to do\nprofiling. If the reader is an avid Python programmer, then it should\nbe possible to use these as a model and create similar (and perchance\nbetter) profile classes.\nIf all you want to do is change how the timer is called, or which\ntimer function is used, then the basic class has an option for that in\nthe constructor for the class. Consider passing the name of a\nfunction to call into the constructor:\nThe resulting profiler will call `your_time_func()` instead of\n`os.times()`. The function should return either a single number\nor a list of numbers (like what `os.times()` returns). If the\nfunction returns a single time number, or the list of returned numbers\nhas length 2, then you will get an especially fast version of the\ndispatch routine.\nBe warned that you should calibrate the profiler class for the\ntimer function that you choose. For most machines, a timer that\nreturns a lone integer value will provide the best results in terms of\nlow overhead during profiling. (os.times is pretty bad, 'cause\nit returns a tuple of floating point values, so all arithmetic is\nfloating point in the profiler!). If you want to substitute a\nbetter timer in the cleanest fashion, you should derive a class, and\nsimply put in the replacement dispatch method that better handles your\ntimer call, along with the appropriate calibration constant :-).\n## Menu", "python_version": "1.2", "length": 1768, "url": "https://docs.python.org/{python_version}/python-lib/profiler_extensions.html"} {"title": "Profiler Introduction -- Python library reference", "text": "Profiler Introduction -- Python library reference\nPrev: The Python Profiler (the_python_profiler.html)\nTop: Top (top.html)\n# 10.1. Introduction to the profiler\nA profiler is a program that describes the run time performance\nof a program, providing a variety of statistics. This documentation\ndescribes the profiler functionality provided in the modules\n`profile` and `pstats.` This profiler provides\ndeterministic profiling of any Python programs. It also\nprovides a series of report generation tools to allow users to rapidly\nexamine the results of a profile operation.", "python_version": "1.2", "length": 573, "url": "https://docs.python.org/{python_version}/python-lib/profiler_introduction.html"} {"title": "pwd -- Python library reference", "text": "pwd -- Python library reference\nPrev: posixpath (posixpath.html)\nTop: Top (top.html)\n# 8.3. Built-in Module `pwd`\nThis module provides access to the UNIX password database.\nIt is available on all UNIX versions.\nPassword database entries are reported as 7-tuples containing the\nfollowing items from the password database (see ), in order:\n`pw_name`,\n`pw_passwd`,\n`pw_uid`,\n`pw_gid`,\n`pw_gecos`,\n`pw_dir`,\n`pw_shell`.\nThe uid and gid items are integers, all others are strings.\nAn exception is raised if the entry asked for cannot be found.\nIt defines the following items:", "python_version": "1.2", "length": 577, "url": "https://docs.python.org/{python_version}/python-lib/pwd.html"} {"title": "Python Services -- Python library reference", "text": "Python Services -- Python library reference\nPrev: Built-in Objects (built-in_objects.html)\nTop: Top (top.html)\n# 3. Python Services\nThe modules described in this chapter provide a wide range of services\nrelated to the Python interpreter and its interaction with its\nenvironment. Here's an overview:\n## Menu", "python_version": "1.2", "length": 307, "url": "https://docs.python.org/{python_version}/python-lib/python_services.html"} {"title": "rand -- Python library reference", "text": "rand -- Python library reference\nPrev: math (math.html)\nTop: Top (top.html)\n# 5.2. Standard Module `rand`\n This module implements a pseudo-random number\ngenerator with an interface similar to `rand()` in C.\nthe following functions:", "python_version": "1.2", "length": 231, "url": "https://docs.python.org/{python_version}/python-lib/rand.html"} {"title": "rect -- Python library reference", "text": "rect -- Python library reference\nPrev: stdwinevents (stdwinevents.html)\nTop: Top (top.html)\n# 15.3. Standard Module `rect`\nThis module contains useful operations on rectangles.\nA rectangle is defined as in module\n`stdwin`:\na pair of points, where a point is a pair of integers.\nFor example, the rectangle\nis a rectangle whose left, top, right and bottom edges are 10, 20, 90\nand 80, respectively.\nNote that the positive vertical axis points down (as in\n`stdwin`).\nThe module defines the following objects:", "python_version": "1.2", "length": 505, "url": "https://docs.python.org/{python_version}/python-lib/rect.html"} {"title": "Reference Manual -- Python library reference", "text": "Reference Manual -- Python library reference\nPrev: Deterministic Profiling (deterministic_profiling.html)\nTop: Top (top.html)\n# 10.5. Reference Manual\nThe primary entry point for the profiler is the global function\n`profile.run()`. It is typically used to create any profile\ninformation. The reports are formatted and printed using methods of\nthe class `pstats.Stats`. The following is a description of all\nof these standard entry points and functions. For a more in-depth\nview of some of the code, consider reading the later section on\nProfiler Extensions, which includes discussion of how to derive\n``better'' profilers from the classes presented, or reading the source\ncode for these modules.\n## Menu", "python_version": "1.2", "length": 707, "url": "https://docs.python.org/{python_version}/python-lib/reference_manual.html"} {"title": "regex -- Python library reference", "text": "regex -- Python library reference\nPrev: string (string.html)\nTop: Top (top.html)\n# 4.2. Built-in Module `regex`\nThis module provides regular expression matching operations similar to\nthose found in Emacs. It is always available.\nBy default the patterns are Emacs-style regular expressions; there is\na way to change the syntax to match that of several well-known\nUNIX utilities.\nThis module is 8-bit clean: both patterns and strings may contain null\nbytes and characters whose high bit is set.\nPlease note: There is a little-known fact about Python string\nliterals which means that you don't usually have to worry about\ndoubling backslashes, even though they are used to escape special\ncharacters in string literals as well as in regular expressions. This\nis because Python doesn't remove backslashes from string literals if\nthey are followed by an unrecognized escape character.\nHowever, if you want to include a literal backslash in a\nregular expression represented as a string literal, you have to\nquadruple it. E.g. to extract LaTeX `\\section{...}' headers from a document, you can use this pattern:\n`'\\\\\\\\section{\\(.*\\)}'`.\nThe module defines these functions, and an exception:\nCompiled regular expression objects support these methods:\nCompiled regular expressions support these data attributes:", "python_version": "1.2", "length": 1301, "url": "https://docs.python.org/{python_version}/python-lib/regex.html"} {"title": "regsub -- Python library reference", "text": "regsub -- Python library reference\nPrev: regex (regex.html)\nTop: Top (top.html)\n# 4.3. Standard Module `regsub`\nThis module defines a number of functions useful for working with\nregular expressions (see built-in module `regex`).", "python_version": "1.2", "length": 228, "url": "https://docs.python.org/{python_version}/python-lib/regsub.html"} {"title": "rfc822 -- Python library reference", "text": "rfc822 -- Python library reference\nPrev: sgmllib (sgmllib.html)\nTop: Top (top.html)\n# 11.10. Standard Module `rfc822`\nThis module defines a class, `Message`, which represents a\ncollection of ``email headers'' as defined by the Internet standard\nRFC 822. It is used in various contexts, usually to read such headers\nfrom a file.\nA `Message` instance is instantiated with an open file object as\nparameter. Instantiation reads headers from the file up to a blank\nline and stores them in the instance; after instantiation, the file is\npositioned directly after the blank line that terminates the headers.\nInput lines as read from the file may either be terminated by CR-LF or\nby a single linefeed; a terminating CR-LF is replaced by a single\nlinefeed before the line is stored.\nAll header matching is done independent of upper or lower case;\ne.g. `m['From']`, `m['from']` and `m['FROM']` all yield\nthe same result.\n## Menu", "python_version": "1.2", "length": 919, "url": "https://docs.python.org/{python_version}/python-lib/rfc822.html"} {"title": "rgbimg -- Python library reference", "text": "rgbimg -- Python library reference\nPrev: jpeg (jpeg.html)\nTop: Top (top.html)\n# 12.5. Built-in Module `rgbimg`\nThe rgbimg module allows python programs to access SGI imglib image\nfiles (also known as .rgb files). The module is far from\ncomplete, but is provided anyway since the functionality that there is\nis enough in some cases. Currently, colormap files are not supported.\nThe module defines the following variables and functions:", "python_version": "1.2", "length": 436, "url": "https://docs.python.org/{python_version}/python-lib/rgbimg.html"} {"title": "rotor -- Python library reference", "text": "rotor -- Python library reference\nPrev: mpz (mpz.html)\nTop: Top (top.html)\n# 13.3. Built-in Module `rotor`\nThis module implements a rotor-based encryption algorithm, contributed by\nLance Ellinghouse. The design is derived from the Enigma device, a machine\nused during World War II to encipher messages. A rotor is simply a\npermutation. For example, if the character `A' is the origin of the rotor,\nthen a given rotor might map `A' to `L', `B' to `Z', `C' to `G', and so on.\nTo encrypt, we choose several different rotors, and set the origins of the\nrotors to known positions; their initial position is the ciphering key. To\nencipher a character, we permute the original character by the first rotor,\nand then apply the second rotor's permutation to the result. We continue\nuntil we've applied all the rotors; the resulting character is our\nciphertext. We then change the origin of the final rotor by one position,\nfrom `A' to `B'; if the final rotor has made a complete revolution, then we\nrotate the next-to-last rotor by one position, and apply the same procedure\nrecursively. In other words, after enciphering one character, we advance\nthe rotors in the same fashion as a car's odometer. Decoding works in the\nsame way, except we reverse the permutations and apply them in the opposite\norder.\nThe available functions in this module are:\nRotor objects have the following methods:\nAn example usage:\nThe module's code is not an exact simulation of the original Enigma device;\nit implements the rotor encryption scheme differently from the original. The\nmost important difference is that in the original Enigma, there were only 5\nor 6 different rotors in existence, and they were applied twice to each\ncharacter; the cipher key was the order in which they were placed in the\nmachine. The Python rotor module uses the supplied key to initialize a\nrandom number generator; the rotor permutations and their initial positions\nare then randomly generated. The original device only enciphered the\nletters of the alphabet, while this module can handle any 8-bit binary data;\nit also produces binary output. This module can also operate with an\narbitrary number of rotors.\nThe original Enigma cipher was broken in 1944.\nThe version implemented here is probably a good deal more difficult to crack\n(especially if you use many rotors), but it won't be impossible for\na truly skilful and determined attacker to break the cipher. So if you want\nto keep the NSA out of your files, this rotor cipher may well be unsafe, but\nfor discouraging casual snooping through your files, it will probably be\njust fine, and may be somewhat safer than using the Unix crypt\ncommand.", "python_version": "1.2", "length": 2659, "url": "https://docs.python.org/{python_version}/python-lib/rotor.html"} {"title": "select -- Python library reference", "text": "select -- Python library reference\nPrev: socket (socket.html)\nTop: Top (top.html)\n# 7.3. Built-in Module `select`\nThis module provides access to the function `select` available in\nmost UNIX versions. It defines the following:", "python_version": "1.2", "length": 226, "url": "https://docs.python.org/{python_version}/python-lib/select.html"} {"title": "Sequence Types -- Python library reference", "text": "Sequence Types -- Python library reference\nPrev: Numeric Types (numeric_types.html)\nTop: Top (top.html)\n## 2.1.5. Sequence Types\nThere are three sequence types: strings, lists and tuples.\nStrings literals are written in single or double quotes:\n`'xyzzy'`, `\"frobozz\"`. See Chapter 2 of the Python\nReference Manual for more about string literals. Lists are\nconstructed with square brackets, separating items with commas:\n`[a, b, c]`. Tuples are constructed by the comma operator (not\nwithin square brackets), with or without enclosing parentheses, but an\nempty tuple must have the enclosing parentheses, e.g.,\n`a, b, c` or `()`. A single item tuple must have a trailing\ncomma, e.g., `(d,)`.\nSequence types support the following operations. The `in' and\n`not,in' operations have the same priorities as the comparison\noperations. The `+' and `*' operations have the same\npriority as the corresponding numeric operations.(1) (#footnotetext1)\nThis table lists the sequence operations sorted in ascending priority\n(operations in the same box have the same priority). In the table,\ns and t are sequences of the same type; n, i\nand j are integers:\nNotes:\n## Menu\n## ---------- Footnotes ----------\n(1) (#footnoteref1)\nThey must\nhave since the parser can't tell the type of the operands.", "python_version": "1.2", "length": 1278, "url": "https://docs.python.org/{python_version}/python-lib/sequence_types.html"} {"title": "SGI IRIX Specific Services -- Python library reference", "text": "SGI IRIX Specific Services -- Python library reference\nPrev: Standard Windowing Interface (standard_windowing_interface.html)\nTop: Top (top.html)\n# 16. SGI IRIX Specific Services\nThe modules described in this chapter provide interfaces to features\nthat are unique to SGI's IRIX operating system (versions 4 and 5).\n## Menu", "python_version": "1.2", "length": 322, "url": "https://docs.python.org/{python_version}/python-lib/sgi_irix_specific_services.html"} {"title": "sgmllib -- Python library reference", "text": "sgmllib -- Python library reference\nPrev: htmllib (htmllib.html)\nTop: Top (top.html)\n# 11.9. Standard Module `sgmllib`\nThis module defines a class `SGMLParser` which serves as the\nbasis for parsing text files formatted in SGML (Standard Generalized\nMark-up Language). In fact, it does not provide a full SGML parser\n--- it only parses SGML insofar as it is used by HTML, and the module only\nexists as a basis for the `htmllib` module.\nIn particular, the parser is hardcoded to recognize the following\nelements:\n- • Opening and closing tags of the form\n```< tag attr =\" value \" ...>`'' and\n````'', respectively.\n• Character references of the form ```&# name ;`''.\n• Entity references of the form ```& name ;`''.\n• SGML comments of the form ```