因此,我在单独的文件"types.py"中定义了几个命名元组:
import collections
TestWindow = collections.namedtuple('TestWindow', 'HWND rect x y w h refPoint')
Point = collections.namedtuple('Point', 'x y')
并希望将这些类型导入到另一个文件中:
from types import TestWindow, Point
def main():
pass
一旦我添加了第一个导入行,我就会得到:
Traceback (most recent call last):
File "main.py", line 1, in <module>
from types import TestWindow, Point
ImportError: cannot import name 'TestWindow'
这里有什么问题?
stdlib 中有一个名为 types
的模块,它被导入了。
重命名模块,或切换到绝对导入。