after struggling trying to figure out how to use python to save the output of the "top" linux command to a variable and then using grep to get a line, I couldn't make it.
I have read in the python documentation about the use of the subprocess module but this doesn't seem to work properly. That is because when you run the top command in linux, you get an alive windows that is refreshing continuously. "Top" is not the same as "ls" or "cp".
So my question is this: How can i use python to get system statistics like CPU percentages etc? (preferebly using the top command, but it would be okay if i would use another command or if i were to read the statistics from a file)
Thanks in advance.