【问题标题】:Python open file in specific application using xdg-utils?Python使用xdg-utils在特定应用程序中打开文件?
【发布时间】:2014-05-20 20:23:38
【问题描述】:

我的 python 脚本中有这行代码:

            os.system("xdg-open " + "User_interaction.py")

它工作正常并在与 .py 文件类型关联的默认应用程序中打开 python 文件,但我希望它运行该文件。我知道我通常可以只导入模块,但 user_interaction 文件已经在导入写入代码的文件,因此它们无法相互导入。

如何让 python 脚本执行 user_interaction 脚本?

干杯。

【问题讨论】:

  • 一般来说,如果你的模块中有循环依赖,你就做错了,应该考虑重构来打破循环。
  • xdg-utils 不是特定于 linux 的:它可以在任何兼容 xdg 的系统上运行
  • 我同意,但遗憾的是,我的项目需要几天时间才能完成,所以我没有时间返工。这是我的第一个 python 项目,所以我想重写它。写得太差了,但是很好!

标签: python xdgutils


【解决方案1】:

你可以在你的文件中包含这个os.system('python file.py')

test.py

import os
os.system('python hello.py')

你好.py

print "hello world"

运行python test.py,它会打印出“hello world”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-04
    • 2017-10-14
    • 2017-06-17
    • 1970-01-01
    • 2012-04-08
    • 2014-02-03
    • 1970-01-01
    • 2020-08-11
    相关资源
    最近更新 更多