Skip to content

Instantly share code, notes, and snippets.

@saidsef
Last active October 8, 2020 08:51
Show Gist options
  • Save saidsef/7b5facc8c204884db4703d75dba6c9fd to your computer and use it in GitHub Desktop.
Save saidsef/7b5facc8c204884db4703d75dba6c9fd to your computer and use it in GitHub Desktop.
Get total physical memory in Python
#!/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