Python 跨平台 os.system

标签 python

目前我的 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/

相关文章:

python - Django 的管理界面不应该用于什么?

python - 比较 pandas groupby 中的最后一个值

python - Flask session 变量在请求之间不持久

python - 为什么pystan安装这么慢?

python - 如何比较两个 OrderedDict 字典?

python - 使用Python进行Elasticsearch多重查询/搜索

python - Matplotlib:具有多种颜色的 y 轴标签

python 池不会按列表中的每个项目运行函数

python - 如何在 Python 3 中计算并打印之间的颜色

python - 对奇数和偶数列表进行排序