小编use*_*699的帖子

使用python保存顶级输出

我已经用 Python 玩了将近五天了,老实说我很喜欢它。
我有这个挑战,我无法解决它。
挑战是每 10 秒重复一次 top 命令的输出并将其保存到文件中。
这是我到目前为止所做的。

import time, os, threading

def repeat():
    print(time.ctime())
    threading.Timer(10, repeat).start()
    f = open('ss.txt', 'w')
    top = os.system("sudo top -p 2948")
    s = str(top)
    text = f.write(s)
    print(text)

repeat()
Run Code Online (Sandbox Code Playgroud)

python

6
推荐指数
2
解决办法
8648
查看次数

标签 统计

python ×1