python3中没有名为copy_reg的模块

时间:2018-03-01 06:54:09

标签: python python-3.x git-submodules python-2.x

我有一个包含此行的git子模块

import copy_reg

适用于Python 2。 但是,Python3中没有名为 copy_reg 的模块。 Python3模块名称为 copyreg

我无法更改git子模块中的代码,因为它将在以后的更新中中断。 如何在不修改模块代码的情况下使代码适用于Python2和Python3。

1 个答案:

答案 0 :(得分:1)

try:
    import copy_reg
except:
    import copyreg as copy_reg