3 Antworten
0
In SoloLearn or on your home computer (local machine)?
0
on my computer
0
Let's say you have two Python script, ScriptMain and ScriptChild. Your problem is that you want to run some funcs of ScriptChild in ScriptMain ?
The right way to do it is to import your Script Child in ScriptMain, then use whatever you need from it (functions and such). Thus just put the header :
import ScriptChild.
They need to be in the same directory. If ScriptChild is sometimes meant to be used as a standalone, you can put everything that ScriptChild should do by itself in a main condition :
if __name__ == '__main__':
# when ScriptChild.py is used as a standalone
#instructions
EDIT : if ScriptChild that you reference has no functions and no main just a block of instructions you want to pass, there is always the dirty way using os.system (so going through your os to launch...) :
os.system("ScriptChild.py 1")