I want to create a python class to encapsulate some global variables:
class TestEnvironment(object):
_on_out = None
# ...
@staticmethod
def onOut():
return TestEnvironment._on_out
@staticmethod
def setOnOut(on_out):
TestEnvironment._on_out = on_out
# -------------------------------------------------------------------- #
def log(msg, process = None):
print msg
# -------------------------------------------------------------------- #
if __name__ == '__main__':
TestEnvironment.setOnOut(log)
print log
print TestEnvironment.onOut()
TestEnvironment.onOut()("A test")
When running I get:
<function log at 0x7fd7738122a8>
<unbound method TestEnvironment.log>
...
TypeError: unbound method log() must be called with TestEnvironment instance as first argument (got str instance instead)
Seems that when I set log
into TestEnvironment
it became unbound method.
How can I overpass it?