简体   繁体   English

Python,模块,importError

[英]Python, modules, importError

I have a problem while importing class from another package. 从另一个包导入类时出现问题。 Unfortunately importError occurs. 不幸的是,发生importError。 I will enclose project structure to visualize my problem. 我将封闭项目结构以可视化我的问题。 Import error occurs when adding 'import A' statement. 添加“ import A”语句时发生导入错误。

Class 'Derived' and 'Base' are placed in folder called 'folder' 类“派生”和“基础”放置在名为“文件夹”的文件夹中

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM