问题
I am trying to write a text based game in python that uses a lexicon(A list of accepted inputs and their grammatical parts). Say I have a file lexicon.txt that contains a list of accepted terms for each room, such as attack(verb), dragon(noun), and up(direction). I know that I could print the contents of that file to my program with lexicon.read()
, but then after the user has played enough that he can't see that part anymore, he might type an unrecognized word. I would rather have the lexicon constantly opened in another window where you could have easy access to it at any time. Is there any way to make my python file import lexicon.txt and open a window of notepad to display the contents?
回答1:
There are many ways to do this.
This opens the file with the default application:
import os
os.startfile(filename)
To open the file explicitly with notepad use this:
import os
os.system("notepad.exe file.txt")
来源:https://stackoverflow.com/questions/26205275/open-a-text-file-window-using-python