私はほぼ 5 日間 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()