简体   繁体   English

如何修复 AttributeError:部分初始化的模块(Visual Studio 2019)

[英]How to fix AttributeError:partially initialized module (Visual Studio 2019)

I'm running the following Python code in Visual Studio:我在 Visual Studio 中运行以下 Python 代码:


app.py |应用程序.py |

from Student import Student

student1 = Student("Jim", "Business", 3.1, False)

print(student1.gpa)

Student.py |学生.py |

class Student:
    def __init__(self, name, major, gps, is_on_probation):
        self.name = name
        self.major = major
        self.gpa = gpa
        self.is_on_probation = is_on_probation

When I try to run it, VS throws the error:当我尝试运行它时,VS 会抛出错误:

cannot import name 'Student' from partially initialized module 'Student' (most likely due to a circular import) (C:\Users\cdegr\source\repos\Student\Student.py)

There was a similar question that I saw, but there wasn't any fix posted for the original question.我看到了一个类似的问题,但没有针对原始问题发布任何修复。 Only requests to see the code posted, so here's mine.只要求查看发布的代码,所以这是我的。 Why is my code not working?为什么我的代码不起作用?

Your class name and your python file name are the same (Student).您的 class 名称和您的 python 文件名相同(学生)。 This causes the error, and the suspicion of circular imports.这会导致错误,并怀疑循环导入。 Rename the class or the python file name, and app.py should work.重命名 class 或 python 文件名,app.py 应该可以工作。

Sidenote: in the __init__ function, your gpa parameter is spelled as gps , so you should fix that.旁注:在__init__ function 中,您的gpa参数拼写为gps ,因此您应该修复它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 AttributeError:部分初始化的模块? - How to fix AttributeError: partially initialized module? 如何修复 AttributeError:部分初始化模块“numpy1”? - How to fix AttributeError: partially initialized module 'numpy1'? Python AttributeError:部分初始化模块 - Python AttributeError: partially initialized module 如何修复“AttributeError:部分初始化的模块‘SendEmail’没有属性‘send_email’(很可能是由于循环导入)” - How to fix 'AttributeError: partially initialized module 'SendEmail' has no attribute 'send_email' (most likely due to a circular import)' AttributeError:部分初始化的模块“pandas”没有属性“read_csv”(很可能是由于循环导入)。 我如何解决它? - AttributeError: partially initialized module 'pandas' has no attribute 'read_csv' (most likely due to a circular import). How do I fix it? AttributeError:部分初始化的模块(文件名不同) - AttributeError: partially initialized module (NOT SAME FILE NAME) AttributeError:部分初始化的模块“pandas”没有属性“DataFrame” - AttributeError: partially initialized module 'pandas' has no attribute 'DataFrame' Python/Json AttributeError:部分初始化的模块“json”没有属性 - Python/Json AttributeError: partially initialized module 'json' has no attribute 不断收到这个 AttributeError:部分初始化的模块 'schedule' 没有属性 'every' - Keep getting this AttributeError: partially initialized module 'schedule' has no attribute 'every' attributererror: 部分初始化的模块“turtle”没有属性“bgcolor” - attributeerror: partially initialized module 'turtle' has no attribute 'bgcolor'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM