I have two different .py file, is it possible to use variables of one in the other?
Sorry for my bad code but I'm still learning :)
In MainFile.py
from LoginFile import login
class MyApp(QtGui.QDialog, Ui_login_dialog):
def __init__(self, parent=None):
super(MyApp,self).__init__()
self.setupUi(self)
self.login_btn.clicked.connect(self.loginCheck)
self.Register.clicked.connect(self.registerCheck)
self.window2 = None
total_usernames = c.execute("SELECT USERNAME FROM register_table").fetchall()
for data in total_usernames:
self.comboBox.addItems(data)
def login_check(self):
username = str(self.comboBox.currentText())
password = str(self.fieldpassword.text())
login(username, password)
# I can't read the following variables from the other file
print(current_status)
print(current_username)
In LoginFile.py I have:
def login(username, password):
driver=webdriver.Chrome(r"C:\Python27\selenium\webdriver\chromedriver.exe")
driver.get(site)
current_username = driver.find_element_by_xpath(".//*[@id='react-root']/section/main/article/header/div[2]/ul/li[1]/span/span").text
current_status = driver.find_element_by_xpath(".//*[@id='react-root']/section/main/article/header/div[2]/ul/li[2]/a/span").text
Basically I would like to read "current_status" and "current_username" variables in MainFile.py imported from LoginFile.py
I already tried to import everything from the other file, with:
from LoginFile import *
but it doesn't work. I also tried to check answers from similar questions, but I wasn't able to find a solution that work in my case.
Is it possible to do it? is there a better solution to arrive to the same result?
Many thanks in advance!!!
__init__.pyin the same directory?loginin yourmain.pyfile,print(current_status)would still fail.login(username, password)just calls the function and throws away any value, so at a minimum, you would need toreturnsomething fromloginand then assign it to something insidelogin_check.