【问题标题】:How to store output from a python file into a variable如何将python文件的输出存储到变量中
【发布时间】:2014-03-10 10:51:29
【问题描述】:

我在 python 脚本中调用一个可执行文件,它在终端中给出如下输出:

迭代次数:150

每步的平均时间为 0.306834 毫秒

平均碰撞时间为 0.027553 毫秒

速度更新的平均时间为 0.109900 毫秒

位置更新的平均时间为 0.031053 毫秒

总循环时间为 46.2161 毫秒

但我想将此文本存储在一个变量中,以便我可以对其进行编辑。这个怎么办???

【问题讨论】:

  • output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]

标签: python terminal output


【解决方案1】:

使用subprocess。它允许您重定向输出。你可以这样做:

output = subprocess.check_output(args)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-11
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多