[英]Why can't I run my python file from another?
import student
^Is at the top of my file. ^位于文件的顶部。
self.studentPage = student.WindowStudent()
Is being run from in a function in a class. 从类中的函数中运行。 WindowStudent is the function to be run in the file being opened in student.py
WindowStudent是要在student.py中打开的文件中运行的函数
The class to be run is set up like this... 这样运行的类设置如下:
class WindowStudent(QtGui.QMainWindow):
def __init__(self):
ETC
AttributeError: 'module' object has no attribute 'WindowStudent'
This is my error? 这是我的错误吗? Does python think the file I'm importing is a module?
python是否认为我要导入的文件是模块?
TIA for any help. TIA寻求任何帮助。
If the import is succeeding but it's not finding the class defined in the file, it could be that you're importing the wrong file. 如果导入成功,但是找不到文件中定义的类,则可能是您导入了错误的文件。
Where you have your import statement, add a line to print the file path location of the imported moduled, as follows: 在具有import语句的位置,添加一行以打印导入的moduled的文件路径位置,如下所示:
import student
print(student.__file__)
Check the path that is output and compare to the file you want to import. 检查输出的路径,并与要导入的文件进行比较。
Check the indentation on your class WindowStudent
in the student.py
file. 检查
student.py
文件中WindowStudent
类的缩进。 If it is indented incorrectly it may appear as a child of another class/function, and so not be available in the module outer scope. 如果缩进不正确,它可能会显示为另一个类/函数的子级,因此在模块外部范围中不可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.