ref: 688c1f15cdaa5fcad19d9fddb30e1c555bfc59e0
dir: /sys/src/cmd/python/Doc/lib/libnew.tex/
\section{\module{new} --- Creation of runtime internal objects} \declaremodule{builtin}{new} \sectionauthor{Moshe Zadka}{[email protected]} \modulesynopsis{Interface to the creation of runtime implementation objects.} The \module{new} 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 \module{new} module defines the following functions: \begin{funcdesc}{instance}{class\optional{, dict}} This function creates an instance of \var{class} with dictionary \var{dict} without calling the \method{__init__()} constructor. If \var{dict} is omitted or \code{None}, 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. \end{funcdesc} \begin{funcdesc}{instancemethod}{function, instance, class} This function will return a method object, bound to \var{instance}, or unbound if \var{instance} is \code{None}. \var{function} must be callable. \end{funcdesc} \begin{funcdesc}{function}{code, globals\optional{, name\optional{, argdefs\optional{, closure}}}} Returns a (Python) function with the given code and globals. If \var{name} is given, it must be a string or \code{None}. If it is a string, the function will have the given name, otherwise the function name will be taken from \code{\var{code}.co_name}. If \var{argdefs} is given, it must be a tuple and will be used to determine the default values of parameters. If \var{closure} is given, it must be \code{None} or a tuple of cell objects containing objects to bind to the names in \code{\var{code}.co_freevars}. \end{funcdesc} \begin{funcdesc}{code}{argcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab} This function is an interface to the \cfunction{PyCode_New()} C function. %XXX This is still undocumented!!!!!!!!!!! \end{funcdesc} \begin{funcdesc}{module}{name[, doc]} This function returns a new module object with name \var{name}. \var{name} must be a string. The optional \var{doc} argument can have any type. \end{funcdesc} \begin{funcdesc}{classobj}{name, baseclasses, dict} This function returns a new class object, with name \var{name}, derived from \var{baseclasses} (which should be a tuple of classes) and with namespace \var{dict}. \end{funcdesc}