简体   繁体   English

为什么我不能从另一个运行我的python文件?

[英]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寻求任何帮助。

Wrong file 文件错误

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. 检查输出的路径,并与要导入的文件进行比较。

Wrong indentation 缩进错误

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.

相关问题 为什么我不能通过我的 cmd 成功运行这个 python 文件? [等候接听] - Why can't I successfully run this python file through my cmd? [on hold] 为什么我可以从 python 文件而不是笔记本运行我的 PyTorch 数据集文件? - Why can I run my PyTorch dataset file from a python file but not a notebook? 为什么我不能在Python Shell中运行代码? - Why can't I run my codes in Python Shell? 为什么我不能从命令提示符运行 python 代码? - Why can't I run python code from my command prompt? 为什么我不能在Pycharm上运行文件? - Why can't i run my file on Pycharm? 无法从另一个python .py文件运行进程 - Can't run process from another python .py file 我无法在 vscode 中运行代码或调试我的 python 文件 - I can't run code or debug of my python file in vscode 为什么我不能在另一个.py文件中使用其中一个.py文件中的方法? - Why I can't use method from one of my .py files in another .py file? 为什么我的Python程序无法正常运行? 它可以运行,但没有得到我想要的结果 - Why my Python program can't run correctly? It can run but don't get the result I want to 为什么我不能在 python 中运行同一个类的方法? - Why can't i run a method from the same class in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM