8.16. new — Creation of runtime internal objects - Python 2.7.18 documentation 编辑

Deprecated since version 2.6: The new module has been removed in Python 3. Use the types module’s classes instead.

The 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 new module defines the following functions:

new.instance(class[, dict])

This function creates an instance of class with dictionary dict without calling the __init__() constructor. If dict is omitted or 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.

new.instancemethod(function, instance, class)

This function will return a method object, bound to instance, or unbound if instance is None. function must be callable.

new.function(code, globals[, name[, argdefs[, closure]]])

Returns a (Python) function with the given code and globals. If name is given, it must be a string or None. If it is a string, the function will have the given name, otherwise the function name will be taken from code.co_name. If argdefs is given, it must be a tuple and will be used to determine the default values of parameters. If closure is given, it must be None or a tuple of cell objects containing objects to bind to the names in code.co_freevars.

new.code(argcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab)

This function is an interface to the PyCode_New() C function.

new.module(name[, doc])

This function returns a new module object with name name. name must be a string. The optional doc argument can have any type.

new.classobj(name, baseclasses, dict)

This function returns a new class object, with name name, derived from baseclasses (which should be a tuple of classes) and with namespace dict.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:86 次

字数:2906

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文