有什么简单的方法可以从Python2迁移到Python3吗

2024-07-04 16:51:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试转换一个名为“PyOPC”的Python2库

但它是巨大的。我使用“2to3库”转换了所有语法。我还替换了一些进口产品,如

删除from expectations import Exceptions

替换了这个

import types as _types
_inttypes = [ _types.IntType, _types.LongType ]
_floattypes = [ _types.FloatType ]
_seqtypes = [ _types.TupleType, _types.ListType ]
_stringtypes = [ _types.StringType, _types.UnicodeType ]

用这个

_inttypes = [ int ]
_floattypes = [ float ]
_seqtypes = [ tuple,list ]
_stringtypes = [ str ]

from UserDict import UserDict替换为from collections import UserDict

还有很多变化。但我怀疑上述变化可能导致了这个问题。以上更改是否正确?有什么简单的方法可以从Python2切换到Python3吗

我找不到任何用于python3的OPC库。只有OpenOPC可用。但不支持使用用户名&;连接;密码


Tags: fromimportas语法exceptionstypespython2expectations

热门问题