From new import of classobj in Python 3.1

How can I modify the given python 2.x statement to compile it in 3.1.

A line of code that does not work.

from new import classobj

Error: "There is no new module."

+3
source share
3 answers

In Python 2.x new.classobj, the type of old-style types. There are no old-style types in Python 3.x. To port your code from Python 2.x to Python 3.x, you first need to bring it to the latest Python 2.x standards, in which case it means stop using old-style classes and only use new-style classes.

, classobj classobj type, 2.x, type, Python 3.x

BTW, . PEP 3108 , Python 3.x. :

  • .
  • , .
  • Docstring , 27241
    (2002-06-15).
+4

type:

X = type('X', (object,), {'a': 1})
+3

If you are in a package, you need to change it to relative import:

from .new import classobj
0
source

Source: https://habr.com/ru/post/1792999/


All Articles