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:\Users\xxx\IdeaProjects\python-samples\test.py", line 1, in
from animal import Animal
ModuleNotFoundError: No module named 'animal'
使用 IDEA 运行 python 是否还需要额外的配置,同目录下的模块无法引入...