My use case : I am making a software that is able to run python scripts with some test cases . Just like the online editor that you see in Competitive Programming Websites like SPOJ/ Hackerrank /Code Forces etc.
I have searched SO and following are the solutions that I got for my problem :
- Using
importstatement to import the script and then test on the functions. - Using
os.systemto run the script. - Using
subprocess.Popen()to run the script. - Using
runpymodule.
I am a newbie and really don't know what will be the best option for my case. I would love some guidance from the SO community.
importcan already handle lots of structured data scripts easily. So unless you have a multiple platforms integrating with your data,importshould be working just fine!os.system()otherwise all 3 other options may be used depending on specific features of your application.subprocess.Popen()in favor ofsubprocess.run()if you can. Ifos.system()is acceptable then definitelyrunshould be, too. But generally don't run Python as a subprocess of Python if you don't have a particular reason (like forcing multiprocessing by crude means, or isolating e.g. signal handlers into one process without affecting another).import. But now I am facing a logical error. The problem is that theimportstatements executes only once (even though you call it multiple times in the script)and so , suppose if someone had an error , and he modified the code , then also my script will not import the new code since the old code was imported earlier. Any tips and how to fix this?