Last active
October 8, 2020 08:51
-
-
Save saidsef/7b5facc8c204884db4703d75dba6c9fd to your computer and use it in GitHub Desktop.
Get total physical memory in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Copyright (c) 2018, Said Sef. All rights reserved. | |
# Use of this source code is governed by a BSD-style license that can be | |
class Meminfo(object): | |
def __init__(self): | |
''' Initialize Meminfo class ''' | |
self.mem = dict() | |
def meminfo(self): | |
''' Returns /proc/meminfo in dict() format ''' | |
with open('/proc/meminfo', 'r') as fh: | |
for row in fh: | |
line = row.split(":") | |
self.mem[line[0]] = line[1].strip().split(" ")[0].strip() | |
return self.mem | |
def _info(self): | |
''' Attributes lookup ''' | |
return (type(self), tuple(map(self.__getattribute__))) | |
def _help(self): | |
return 'meminfo() returns available resources from /proc/meminfo in kB' | |
def __del__(self): | |
''' Class destructor ''' | |
del self |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment