To simply open a file in its default application, you can use
import os
file = "C:\\Documents\\file.txt"
os.startfile(file)
This will open the file in whatever application is associated with the file extension.
There are some drawbacks however, so if you want to do some more advanced handling of the file (such as closing it later), you need a more advanced approach. You can try the solution to my question here which shows how to use subprocess.popen()
to keep track of the file, and then close it. Here's the general idea:
>>> import psutil
>>> import subprocess
>>> doc = subprocess.Popen(["start", "/WAIT", "file.pdf"], shell=True) #Stores the open file as doc
>>> doc.poll() #Shows that the process still exists (will return 0 if the /WAIT argument is excluded from previous line)
>>> psutil.Process(doc.pid).get_children()[0].kill() #Kills the process
>>> doc.poll() #Shows that the process has been killed
0
>>>
This retains the file you opened as the doc
object so that it can be easily closed later