0

Hi everyone how can i run a python script from another one ?? I've tryed many thing but no Solution

python

26th Sep 2018, 12:04 PM
romene hassen
3 Answers
0
In SoloLearn or on your home computer (local machine)?
26th Sep 2018, 12:54 PM
Janning⭐
Janning⭐ - avatar
0
on my computer
26th Sep 2018, 12:57 PM
romene hassen
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")
26th Sep 2018, 2:19 PM
dhm