简体   繁体   English

如何从另一个重新定义的 python 文件中调用变量

[英]How can I call a variable from another python file which is re-defined

in file1, value of "source" is changed depends on which button I click.在 file1 中,“源”的值会根据我点击的按钮而改变。

source = 0
form_class2 = uic.loadUiType("./UI/Code.ui")[0]
class Code(QDialog, form_class2):
def __init__(self):
    super().__init__()
    self.setupUi(self)
    self.pushButton.clicked.connect(self.aa)
    self.pushButton_2.clicked.connect(self.bb)

def aa(self):
    global source
    source = 1
    app.quit()
        
def bb(self):
    global source
    source = 2
    app.quit()
        
if __name__ == "__main__":
    app = QApplication(sys.argv)
    myWindow = Code()
    myWindow.show()
    app.exec_()

import file2

then in file2:然后在文件2中:

from file1 import source
print(source)

output is 0 output 为 0

How can I get 1 or 2 for the output in flie2?如何在 flie2 中获得 output 的 1 或 2?

Maybe this can help you也许这可以帮助你

from file1 import *  

暂无
暂无

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

相关问题 如何从 Python 中的另一个文件调用 function 中定义的变量? - How can I call a variable defined inside a function from another file in Python? 如何确定要在python中定义的函数使用哪个变量 - How can I determine which variable to use for a defined function in python 如何在python中另一个文件下的另一个类中调用一个方法? - How can I call a method which is in another class under another file in python? 如何从另一个文件中打印python中的变量 - how can I print variable in python from another file 如何从C ++调用另一个文件中定义的python函数? - How to call a python function defined in another file from c++? 我如何向 python 中的字典添加内容,该内容存在于另一个 python 文件的另一个文件中 - how can i add something to a dictionary in python which is present in another file from another python file 当我运行一个调用另一个 python 文件时,如何将一些 arguments 传递给它? - when I run a python file which call another one ,how can I pass some arguments to it? 如何从python中的另一个文件访问构造函数中定义的变量 - How to access variable defined in constructor from another file in python 为什么Python中的此1-D数组被自动关联时会被更改/重新定义? - Why does this 1-D array in python get altered / re-defined while being autocorrelated? 如何更改另一个文件中定义的变量? - How can I change a variable defined in another file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM