Skip to content

Instantly share code, notes, and snippets.

@SpEcHiDe
Last active August 16, 2016 16:12
Show Gist options
  • Save SpEcHiDe/cdd30925662b066c707e2fdaee8de7df to your computer and use it in GitHub Desktop.
Save SpEcHiDe/cdd30925662b066c707e2fdaee8de7df to your computer and use it in GitHub Desktop.
#DGPLUG
#!/usr/bin/env python2
def read_file(filename, numlines) :
'''
reads the first numlines of lines from filename
'''
d = []
with open(filename) as f :
for line in f :
if numlines == 0 :
break
else :
d.append(line)
numlines -= 1
return d
def parse_line_info(lineval) :
'''
returns the numerical part of a string in the format a: b c
'''
lst = lineval.split(" ")
kb_val = lst[-2]
return kb_val
def KB2MB(value) :
'''
converts kilobyte value to mega byte value and appends MB at the end
'''
mbval = (int(v) * 1.0) / 1024
return str(mbval) + " MB"
if __name__ == "__main__" :
file_lst = read_file("/proc/meminfo", 3)
for values in file_lst :
print KB2MB(parse_line_info(values))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment