electron1
electron1

Reputation: 97

Does a file opened with os.system() have to be closed before the program continues?

I am writing a text based game in python that requires uses a lexicon. I need to be able to leave the text file open while the rest of the program is running. Is there any way to do this, or does the opened file have to be closed before the program can continue. Here is my earlier question that describes why I need the opened file: Open a text file window using Python

Upvotes: 0

Views: 634

Answers (1)

Tony Suffolk 66
Tony Suffolk 66

Reputation: 9714

Based on your other question, you are using os.system not to open the file specifically, but to open an external editor to display/edit a file.

os.system is a "synchronous" call, which in this case means that the python code after os.system wont run until the edit program exits.

if you want your code to run while the editor is running - then you will need to find another way to do that :

  • look at parts of the subprocess module to allow you to run your external editor in a way that is not synchronous (this is called asynchronous) - use subprocess.popen
  • find a different way to display/edit the text that does not require an external editor

Upvotes: 1

Related Questions