I am trying to initialize a class attribute by calling a function. Please see below. This code works as expected meanwhile it makes me confused. To my understanding getmemtoto is a so-called unbound function which need to be called with a instance of class T. How could it be called during the class definition?
class T:
def getmemtot():
output=shell(r"sed -r -n -e 's/^MemTotal:\s*([[:digit:]]+)\s*kB/\1/ p' /proc/meminfo")
return int(output)
MEMTOT=T.getmemtot()
If I tried to call getmemtot directly I got below errors:
>>> T.getmemtot()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method getmemtot() must be called with T instance as first argument (got nothing instead)
>>> getmemtot()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'getmemtot' is not defined