How would I go about opening a file in Python by referring to a text file. EXAMPLE:
f.open('openthis.txt')
Then I would have openthis.txt in the same folder that would say:
C:\\Folder\\myprogram.exe
Therefore the code opens up myprogram.exe from the directory
I want to do this so the code is easily changable, instead of having to edit it in IDLE every time I want to change the file I open.
You want the subprocess module. Specifically, you'd do something like:
import subprocess
with open("inputfile", "rb") as f:
subprocess.call(f.read())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.