Open File using Specific Application in Python

In the following programs you will learn that how to open specific computer file by using specific application.

Program Opening Text File Using Notepad

Program

import os #opening 'MyTxtFile.txt' using NotePad.
print("Opening MyTxtFile text file using notepad application")
osCommandString = "notepad.exe C://MyTxtFile.txt"
os.system(osCommandString)
Output
Opening MyTxtFile text file using notepad application

Program Opening Text File Using Notepad Another Method

Program

import subprocess as sp
print("Opening MyTxtFile text file using notepad application")
programName = "notepad.exe" #opening 'MyTxtFile.txt'
fileName = "C://MyTxtFile.txt" #using Notepad.
sp.Popen([programName, fileName])
Output
Opening MyTxtFile text file using notepad application

Program Opening Text File Using Notepad Another Method

Program

import subprocess
print("Opening MyTxtFile text file using notepad application")
subprocess.call(["notepad.exe", "C://MyTxtFile.txt"])
Output
Opening MyTxtFile text file using notepad application

Program Opening Text File Using Default Opener
Program

import subprocess
print("Opening application list to select application to open MyTxtFile text file")
subprocess.call(["cmd.exe", "/c", "C://MyTxtFile.txt"])
Output
Opening application list to select application to open MyTxtFile text file