| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="module-site.html" /> |
| 13 | <link rel="prev" href="module-repr.html" /> |
| 14 | <link rel="parent" href="python.html" /> |
| 15 | <link rel="next" href="module-site.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>3.29 new -- Creation of runtime internal objects</title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="3.28.2 Subclassing Repr Objects" |
| 25 | href="subclassing-reprs.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="3. Python Runtime Services" |
| 28 | href="python.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="3.30 site " |
| 31 | href="module-site.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="subclassing-reprs.html">3.28.2 Subclassing Repr Objects</A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="module-site.html">3.30 site </A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H1><A NAME="SECTION0052900000000000000000"> |
| 56 | 3.29 <tt class="module">new</tt> -- |
| 57 | Creation of runtime internal objects</A> |
| 58 | </H1> |
| 59 | |
| 60 | <P> |
| 61 | <A NAME="module-new"></A> |
| 62 | |
| 63 | <P> |
| 64 | The <tt class="module">new</tt> module allows an interface to the interpreter object |
| 65 | creation functions. This is for use primarily in marshal-type functions, |
| 66 | when a new object needs to be created ``magically'' and not by using the |
| 67 | regular creation functions. This module provides a low-level interface |
| 68 | to the interpreter, so care must be exercised when using this module. |
| 69 | It is possible to supply non-sensical arguments which crash the |
| 70 | interpreter when the object is used. |
| 71 | |
| 72 | <P> |
| 73 | The <tt class="module">new</tt> module defines the following functions: |
| 74 | |
| 75 | <P> |
| 76 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 77 | <td><nobr><b><tt id='l2h-793' xml:id='l2h-793' class="function">instance</tt></b>(</nobr></td> |
| 78 | <td><var>class</var><big>[</big><var>, dict</var><big>]</big><var></var>)</td></tr></table></dt> |
| 79 | <dd> |
| 80 | This function creates an instance of <var>class</var> with dictionary |
| 81 | <var>dict</var> without calling the <tt class="method">__init__()</tt> constructor. If |
| 82 | <var>dict</var> is omitted or <code>None</code>, a new, empty dictionary is |
| 83 | created for the new instance. Note that there are no guarantees that |
| 84 | the object will be in a consistent state. |
| 85 | </dl> |
| 86 | |
| 87 | <P> |
| 88 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 89 | <td><nobr><b><tt id='l2h-794' xml:id='l2h-794' class="function">instancemethod</tt></b>(</nobr></td> |
| 90 | <td><var>function, instance, class</var>)</td></tr></table></dt> |
| 91 | <dd> |
| 92 | This function will return a method object, bound to <var>instance</var>, or |
| 93 | unbound if <var>instance</var> is <code>None</code>. <var>function</var> must be |
| 94 | callable. |
| 95 | </dl> |
| 96 | |
| 97 | <P> |
| 98 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 99 | <td><nobr><b><tt id='l2h-795' xml:id='l2h-795' class="function">function</tt></b>(</nobr></td> |
| 100 | <td><var>code, globals</var><big>[</big><var>, name</var><big>[</big><var>, argdefs</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 101 | <dd> |
| 102 | Returns a (Python) function with the given code and globals. If |
| 103 | <var>name</var> is given, it must be a string or <code>None</code>. If it is a |
| 104 | string, the function will have the given name, otherwise the function |
| 105 | name will be taken from <code><var>code</var>.co_name</code>. If |
| 106 | <var>argdefs</var> is given, it must be a tuple and will be used to |
| 107 | determine the default values of parameters. |
| 108 | </dl> |
| 109 | |
| 110 | <P> |
| 111 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 112 | <td><nobr><b><tt id='l2h-796' xml:id='l2h-796' class="function">code</tt></b>(</nobr></td> |
| 113 | <td><var>argcount, nlocals, stacksize, flags, codestring, |
| 114 | constants, names, varnames, filename, name, firstlineno, |
| 115 | lnotab</var>)</td></tr></table></dt> |
| 116 | <dd> |
| 117 | This function is an interface to the <tt class="cfunction">PyCode_New()</tt> C |
| 118 | function. |
| 119 | </dl> |
| 120 | |
| 121 | <P> |
| 122 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 123 | <td><nobr><b><tt id='l2h-797' xml:id='l2h-797' class="function">module</tt></b>(</nobr></td> |
| 124 | <td><var>name</var>)</td></tr></table></dt> |
| 125 | <dd> |
| 126 | This function returns a new module object with name <var>name</var>. |
| 127 | <var>name</var> must be a string. |
| 128 | </dl> |
| 129 | |
| 130 | <P> |
| 131 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 132 | <td><nobr><b><tt id='l2h-798' xml:id='l2h-798' class="function">classobj</tt></b>(</nobr></td> |
| 133 | <td><var>name, baseclasses, dict</var>)</td></tr></table></dt> |
| 134 | <dd> |
| 135 | This function returns a new class object, with name <var>name</var>, derived |
| 136 | from <var>baseclasses</var> (which should be a tuple of classes) and with |
| 137 | namespace <var>dict</var>. |
| 138 | </dl> |
| 139 | |
| 140 | <DIV CLASS="navigation"> |
| 141 | <div class='online-navigation'> |
| 142 | <p></p><hr /> |
| 143 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 144 | <tr> |
| 145 | <td class='online-navigation'><a rel="prev" title="3.28.2 Subclassing Repr Objects" |
| 146 | href="subclassing-reprs.html"><img src='../icons/previous.png' |
| 147 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 148 | <td class='online-navigation'><a rel="parent" title="3. Python Runtime Services" |
| 149 | href="python.html"><img src='../icons/up.png' |
| 150 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 151 | <td class='online-navigation'><a rel="next" title="3.30 site " |
| 152 | href="module-site.html"><img src='../icons/next.png' |
| 153 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 154 | <td align="center" width="100%">Python Library Reference</td> |
| 155 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 156 | href="contents.html"><img src='../icons/contents.png' |
| 157 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 158 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 159 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 160 | <td class='online-navigation'><a rel="index" title="Index" |
| 161 | href="genindex.html"><img src='../icons/index.png' |
| 162 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 163 | </tr></table> |
| 164 | <div class='online-navigation'> |
| 165 | <b class="navlabel">Previous:</b> |
| 166 | <a class="sectref" rel="prev" href="subclassing-reprs.html">3.28.2 Subclassing Repr Objects</A> |
| 167 | <b class="navlabel">Up:</b> |
| 168 | <a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A> |
| 169 | <b class="navlabel">Next:</b> |
| 170 | <a class="sectref" rel="next" href="module-site.html">3.30 site </A> |
| 171 | </div> |
| 172 | </div> |
| 173 | <hr /> |
| 174 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 175 | </DIV> |
| 176 | <!--End of Navigation Panel--> |
| 177 | <ADDRESS> |
| 178 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 179 | </ADDRESS> |
| 180 | </BODY> |
| 181 | </HTML> |