目前我的 Python 程序打开一个这样的文本文件:
os.system('gedit decryptedText.txt&')
现在,我认为这在 Windows 上不起作用,因为 gedit 是一个 Linux 应用程序?我怎样才能让它在 Windows 和 Linux 上运行。或者它对两者都有效?
最佳答案
先检查操作系统,然后根据结果分配?
if os.name == 'nt':
os.system('notepad ecryptedText.txt&')
elif os.name == 'posix':
os.system('gedit decryptedText.txt&')
关于Python 跨平台 os.system,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12584647/