[英]Python, modules, importError
从另一个包导入类时出现问题。 不幸的是,发生importError。 我将封闭项目结构以可视化我的问题。 添加“ import A”语句时发生导入错误。
类“派生”和“基础”放置在名为“文件夹”的文件夹中
from folder.Derived import Derived
class A:
pass
import A
#The line above causes importError
class Base:
pass
from folder.Base import Base
class Derived(Base):
pass
您不能从A导入A,因为您没有A。如果A用于衍生用途:
from Derived import A
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.