This is the way i call a .py file within a folder from a .pyw file outside, i am able to do that successfully, but want to know how can i pass variable from this .pyw file to the .py file within a folder.
if int(verfyUser) == int(Username):
path = self.application.applicationDirectory
name = "User_UI"
path = os.path.join(self.application.applicationDirectory, name)
if os.path.exists(os.path.join(path, name + ".pyw")):
filename = os.path.join(path, name + ".pyw")
else:
filename = os.path.join(path, name + ".py")
args = []
if ' ' in filename:
filename = '"' + filename + '"'
python = sys.executable
self.close()
if ' ' in python:
pythonQuoted = '"' + python + '"'
else:
pythonQuoted = python
os.spawnv(os.P_NOWAIT, python, [pythonQuoted, filename] + args)
i tried to pass the variables in args[], but that's not the way. Please to help me. Want to find a way to pass the variable from .pyw to the calling py file. Hope i am clear.....
How do you want to pass the variables? Just the values? In that case your approach seems good: you can call the other Python script with the values as command-line arguments. Your other script should then parse the command-line arguments that it has received and utilize them in the code.
But, just to be sure, you cannot write variable = 3
in the current script, then spawn a separate Python script and then use variable
right away somehow.