currently my Python program opens a text file like this:
os.system('gedit decryptedText.txt&')
Now, I presume this will not work on Windows, since gedit is a Linux application? How can I make this run on both Windows and Linux. Or will it work on both?
Check for OS first, and assign depending on result?
if os.name == 'nt':
os.system('notepad ecryptedText.txt&')
elif os.name == 'posix':
os.system('gedit decryptedText.txt&')
On MS Windows you could use os.startfile(filename) for file types that have associated editors.
Hence your full solution would be something like:
def start_file(filename):
if os.name == 'nt':
os.startfile(filename)
else:
os.system('gedit %s&' % filename)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With