-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcpuinfo.py
More file actions
30 lines (27 loc) · 755 Bytes
/
Copy pathcpuinfo.py
File metadata and controls
30 lines (27 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python
#
# Get CPU Info of RaspberrPi for only one core.
# (c) 10.2015 by meigrafd
#
from __future__ import print_function
def get_cpu_info():
info = [{}]
try:
fo = open('/proc/cpuinfo')
except EnvironmentError, e:
print("Error:", str(e))
else:
for line in fo:
name_value = [s.strip() for s in line.split(':', 1)]
if len(name_value) != 2:
continue
name, value = name_value
info[-1][name] = value
fo.close()
return info[0]
if __name__ == '__main__':
cpu_info = get_cpu_info()
for name in cpu_info:
print("{0:16}: {1}" . format(name, cpu_info[name]))
#only print 'Serial' info:
print(cpu_info['Serial'])