<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"lib.html" title='Python Library Reference'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"module-site.html" />
<link rel=
"prev" href=
"module-repr.html" />
<link rel=
"parent" href=
"python.html" />
<link rel=
"next" href=
"module-site.html" />
<meta name='aesop' content='information'
/>
<title>3.29 new -- Creation of runtime internal objects
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"3.28.2 Subclassing Repr Objects"
href=
"subclassing-reprs.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"3. Python Runtime Services"
href=
"python.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"3.30 site "
href=
"module-site.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"subclassing-reprs.html">3.28.2 Subclassing Repr Objects
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"python.html">3. Python Runtime Services
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"module-site.html">3.30 site
</A>
<!--End of Navigation Panel-->
<H1><A NAME=
"SECTION0052900000000000000000">
3.29 <tt class=
"module">new
</tt> --
Creation of runtime internal objects
</A>
<A NAME=
"module-new"></A>
The
<tt class=
"module">new
</tt> module allows an interface to the interpreter object
creation functions. This is for use primarily in marshal-type functions,
when a new object needs to be created ``magically'' and not by using the
regular creation functions. This module provides a low-level interface
to the interpreter, so care must be exercised when using this module.
It is possible to supply non-sensical arguments which crash the
interpreter when the object is used.
The
<tt class=
"module">new
</tt> module defines the following functions:
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
793' xml:id='l2h-
793'
class=
"function">instance
</tt></b>(
</nobr></td>
<td><var>class
</var><big>[
</big><var>, dict
</var><big>]
</big><var></var>)
</td></tr></table></dt>
This function creates an instance of
<var>class
</var> with dictionary
<var>dict
</var> without calling the
<tt class=
"method">__init__()
</tt> constructor. If
<var>dict
</var> is omitted or
<code>None
</code>, a new, empty dictionary is
created for the new instance. Note that there are no guarantees that
the object will be in a consistent state.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
794' xml:id='l2h-
794'
class=
"function">instancemethod
</tt></b>(
</nobr></td>
<td><var>function, instance, class
</var>)
</td></tr></table></dt>
This function will return a method object, bound to
<var>instance
</var>, or
unbound if
<var>instance
</var> is
<code>None
</code>.
<var>function
</var> must be
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
795' xml:id='l2h-
795'
class=
"function">function
</tt></b>(
</nobr></td>
<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>
Returns a (Python) function with the given code and globals. If
<var>name
</var> is given, it must be a string or
<code>None
</code>. If it is a
string, the function will have the given name, otherwise the function
name will be taken from
<code><var>code
</var>.co_name
</code>. If
<var>argdefs
</var> is given, it must be a tuple and will be used to
determine the default values of parameters.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
796' xml:id='l2h-
796'
class=
"function">code
</tt></b>(
</nobr></td>
<td><var>argcount, nlocals, stacksize, flags, codestring,
constants, names, varnames, filename, name, firstlineno,
lnotab
</var>)
</td></tr></table></dt>
This function is an interface to the
<tt class=
"cfunction">PyCode_New()
</tt> C
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
797' xml:id='l2h-
797'
class=
"function">module
</tt></b>(
</nobr></td>
<td><var>name
</var>)
</td></tr></table></dt>
This function returns a new module object with name
<var>name
</var>.
<var>name
</var> must be a string.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
798' xml:id='l2h-
798'
class=
"function">classobj
</tt></b>(
</nobr></td>
<td><var>name, baseclasses, dict
</var>)
</td></tr></table></dt>
This function returns a new class object, with name
<var>name
</var>, derived
from
<var>baseclasses
</var> (which should be a tuple of classes) and with
namespace
<var>dict
</var>.
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"3.28.2 Subclassing Repr Objects"
href=
"subclassing-reprs.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"3. Python Runtime Services"
href=
"python.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"3.30 site "
href=
"module-site.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"subclassing-reprs.html">3.28.2 Subclassing Repr Objects
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"python.html">3. Python Runtime Services
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"module-site.html">3.30 site
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.