这是我的python项目结构,
test cat Cat.py class Cat dog Dog.py class Dog
将Dog类导入Cat类
时出现模块未找到错误来自dog.Dog import *
如何解决?
答案 0 :(得分:1)
您正在混合概念,请使用:
from dog import Dog
答案 1 :(得分:0)
使用
from dog import Dog
或
from dog import *
代替。
答案 2 :(得分:0)
遵循语法
# To import a module
import [module]
# To import a class from a module
from [module] import [class]
因此,在您的情况下,
# To import a class [Dog] from a module [dog]
from dog import Dog
# To import everything from the module [dog]
import dog # -> Refer your class as dog.Dog
from dog import * # -> Refer your class directly as Dog
import dog as d # -> Refer your class as d.Dog