How to open a program from a text file in Python

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.

Upvotes: 0

Views: 210

Answers (1)

Kyle Maxwell
Kyle Maxwell

Reputation: 627

You want the subprocess module. Specifically, you'd do something like:

import subprocess

with open("inputfile", "rb") as f:
    subprocess.call(f.read())

Upvotes: 1

Related Questions