共计 395 个字符,预计需要花费 1 分钟才能阅读完成。
项目结构如下:
test.py 内容:
from animal import Animal
if __name__ == "__main__":
animal = Animal("小黑")
animal.eat("骨头")
init.py 内容:
class Animal:
# 构造方法
def __init__(self, name):
self.name = name
def eat(self, food):
self.food = food
运行 test.py 报错:
Traceback (most recent call last):
File "C:UsersxxxIdeaProjectspython-samplestest.py", line 1, in
from animal import Animal
ModuleNotFoundError: No module named 'animal'
使用 IDEA 运行 python 是否还需要额外的配置,同目录下的模块无法引入 …
正文完