saving top output using python
<p>I have been playing with Python for almost five days and I honestly enjoy it.<br>
I have this challenge and I couldn't solve it.<br>
The challenge is to repeat the output of top command every 10 seconds and save it into a file.<br>
Here is what I have done so far.</p>

<pre><code>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()
</code></pre>
