You are not logged in.
Hi,
I am trying to get cpu Mhz from cat /proc/cpuinfo...
#!/usr/bin/env python
# Pull Cpu speed from /proc/cpuinfo
import os
import sys
import string
def lin_com(b):
h = os.popen(b)
k = h.readlines()
#k = k[:len(k)-1]
h.close()
return k
g = lin_com("cat /proc/cpuinfo")
g = g[6]
g = g.split(':')[1:]
print g
but I get ['<speed>'/n] wanted to clean up output but not sure how ....
I know cpu speed is in line 6 of array or would it be better to search for string in cpuinfo?
Emm not sure kinda in the dark here .....?
Mr Green
Offline
for your output issue:
g = g.split(':')[1].strip()
I would search for the keywords though instead of using a set line number.
cpu_mhz = ''
for line in k:
if 'MHz' in line:
cpu_mhz = line.split(bla bla)
I would also just open the file instead of using a pipe with cat.
f = os.open('/proc/cpuinfo', 'r')
f.readlines()
f.close()
Offline
Or you could use grep like in:
cat /proc/cpuinfo | grep 'model name'
Offline
cpu_mhz = line.split(bla bla)
I cannot find bla bla in Py docs :? j/k
Yeah I opening file is neater ... I see if I can clean it up a bit. ..
cat /proc/cpuinfo | grep 'cpu Mhz' gives not output here maybe the tabs spaces I don't know .....
f = os.open('/proc/cpuinfo', 'r')
TypeError: an integer is required
very confused.....
Mr Green
Offline
sorry, its open()
Offline
no no dude I got it lol...
/me opens Learn Python in 10 seconds
I get
['', ' MHztt: 3220.212n']
emmm need to pull out digits re maybe?
Mr Green
Offline
>>> for line in lines:
... if 'MHz' in line:
... cpu_MHz = line.split(':')[1].strip()
...
>>> cpu_MHz
'2071.203'
Offline
no waay dude ... Wow!!!! 8)
Now can you wrap it in gtk for me please rofl
Mr Green
Offline