0

So im making a game in Pygame. Whenever player dies the program has to run another file and close itself. for example:

import os 

os.system('python my_file.py')
quit(1)

but this method doesnt really work. When it runs my_file.py it waits for my_file to close and then it runs quit(1) is there any way of making it work? (excluding subprocess popen because i don'r really understand how it works

  • Why do you need to run a different python script? Can you not turn the other file into a module and import that into your code? That would be a lot cleaner – UnholySheep Dec 14 '19 at 17:19
  • Does this answer your question? [How can I make one python file run another?](https://stackoverflow.com/questions/7974849/how-can-i-make-one-python-file-run-another) – Adam Feor Dec 14 '19 at 17:20
  • I actually want to rerun this program but i cant have a main() or rerun() function without rebuilding the whole script/ – dawid kaprol Dec 14 '19 at 17:21
  • Check https://docs.python.org/2/library/subprocess.html this is most likely what do you want. Just pick first correct python version. Alternatively try multithreading. – Zydnar Dec 14 '19 at 17:23
  • Move your globals to some namespace ```function``` better ```class```, so they will stop being a singleton and you will be able to make a while loop for your ```start_game()``` function which will have default values on the next call – IVI Dec 14 '19 at 17:39
  • @AdamFeor yes, I mean kind of. When i run a python file using call `(["python", "your_file.py"])` it doesnt import pygame module. – dawid kaprol Dec 14 '19 at 17:50
  • i get ModuleNotFoundError even though i have it installed – dawid kaprol Dec 14 '19 at 17:51
  • Try using threading, it will quit while running the so. system code – Tommy Lawrence Dec 15 '19 at 03:56

0 Answers0