python - python,Windows 7:ImportError:无法导入名称 X
问题描述
我正在处理两个文件:construct\core.py
和USBtransport.py
. 以下是两个文件中的相关代码:
构造\core.py:
class Range(Subconstruct):
__slots__ = ["min", "max"]
def __init__(self, min, max, subcon):
super(Range, self).__init__(subcon)
self.min = min
self.max = max
....
其中 Subconstruct 是 Construct 的子类,它们都在代码的前面定义。
USB传输.py:
from construct import Subconstruct
from construct import (
Bytes, Container, Embedded, Enum, ExprAdapter, Int16ul, Int32ul, Pass,
Struct, Range,
)
尝试运行 USBtransport.py 时遇到此错误:
ImportError: cannot import name 'Range'
我查看了有关此错误的类似帖子,它们似乎都源于循环导入。但是我认为这不是问题所在,因为core.py
从不调用任何类USBtransport.py
。我也可以毫无问题地导入其他Subconstruct
对象。core.py
我也不认为错误源于类内的代码,Range(Subconstruct)
因为当我注释掉里面的所有代码并尝试导入一个空类时,我得到了同样的错误。
有任何想法吗?
解决方案
您确定您使用的是正确版本的Construct吗?
根据https://construct.readthedocs.io/en/latest/transition29.html,Range
已在 2.9 中删除,因此您可能需要安装 2.8.x。
Range 被移除,GreedyRange 不支持 [:] 语法
推荐阅读
- r - 闪亮的散点图
- clojure - 在宏内部调用匿名函数 n 次,具体取决于作为参数传递给它的数据结构的大小
- couchdb - 在 CouchDB 中创建和查询未知对象键的芒果索引
- javascript - 我应该将静态文件放在我的共享主机帐户中的什么位置?
- asterisk - 星号,键在后台命令上不起作用,就在后台之后
- html - 只有在 ipad 上的 safari 上刷新时才会显示背景图像
- lua - lua lgi 订阅 DBus 信号
- yii - 漂亮的 url 没有在 Yii2 中重定向
- java - java.lang.ClassNotFoundException,命令行制作问题和 bash 脚本
- python - 性能监控工具 vs 进程状态 (ps) 命令