我已经创建了2个Python文件,它保存在OOP_1文件夹中。当我尝试运行时会出现错误,而且在从Python文件导入类时,我无法理解使用.的目的。
我尝试从相关的Python文件中删除.student,.course,但是它不会在main.py中使用from OOP_1 import *运行。
student.py学生: def __init__(self,name,number):self._student_name = name self._student_number =self._student_name
从student_limit
__init__.py导入学生类课程(学生):#实例属性def __init__(self,name,code,credit,student_limit):#构造函数的代码self._name =Nameself._code=Codeself._credit= credit self._student_limit =student_limit从Course
main.py导入.student从.course导入学生从OOP_1导入*
然而,在__init__中,Python给出了一个错误:
ModuleNotFoundError: No module named '__main__.student'; '__main__' is not a package在main.py中,Python给了我:
ModuleNotFoundError: No module named 'course'如何确保我存储类的文件夹在main.py文件中工作?
发布于 2019-10-09 10:09:37
A single leading dot indicates a relative import, starting with the current package.
您需要在当前上下文中拥有这些模块才能像这样导入它们
https://stackoverflow.com/questions/58301483
复制相似问题