/Doc/library/new.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 66 lines · 40 code · 26 blank · 0 comment · 0 complexity · c700cb5481a2f93a4a6cc5a45514ec3d MD5 · raw file

  1. :mod:`new` --- Creation of runtime internal objects
  2. ===================================================
  3. .. module:: new
  4. :synopsis: Interface to the creation of runtime implementation objects.
  5. :deprecated:
  6. .. deprecated:: 2.6
  7. The :mod:`new` module has been removed in Python 3.0. Use the :mod:`types`
  8. module's classes instead.
  9. .. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
  10. The :mod:`new` module allows an interface to the interpreter object creation
  11. functions. This is for use primarily in marshal-type functions, when a new
  12. object needs to be created "magically" and not by using the regular creation
  13. functions. This module provides a low-level interface to the interpreter, so
  14. care must be exercised when using this module. It is possible to supply
  15. non-sensical arguments which crash the interpreter when the object is used.
  16. The :mod:`new` module defines the following functions:
  17. .. function:: instance(class[, dict])
  18. This function creates an instance of *class* with dictionary *dict* without
  19. calling the :meth:`__init__` constructor. If *dict* is omitted or ``None``, a
  20. new, empty dictionary is created for the new instance. Note that there are no
  21. guarantees that the object will be in a consistent state.
  22. .. function:: instancemethod(function, instance, class)
  23. This function will return a method object, bound to *instance*, or unbound if
  24. *instance* is ``None``. *function* must be callable.
  25. .. function:: function(code, globals[, name[, argdefs[, closure]]])
  26. Returns a (Python) function with the given code and globals. If *name* is given,
  27. it must be a string or ``None``. If it is a string, the function will have the
  28. given name, otherwise the function name will be taken from ``code.co_name``. If
  29. *argdefs* is given, it must be a tuple and will be used to determine the default
  30. values of parameters. If *closure* is given, it must be ``None`` or a tuple of
  31. cell objects containing objects to bind to the names in ``code.co_freevars``.
  32. .. function:: code(argcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab)
  33. This function is an interface to the :cfunc:`PyCode_New` C function.
  34. .. XXX This is still undocumented!
  35. .. function:: module(name[, doc])
  36. This function returns a new module object with name *name*. *name* must be a
  37. string. The optional *doc* argument can have any type.
  38. .. function:: classobj(name, baseclasses, dict)
  39. This function returns a new class object, with name *name*, derived from
  40. *baseclasses* (which should be a tuple of classes) and with namespace *dict*.