you can use class methods:
config.py
class var:
def __init__(self, executable):
self.executable = executable
def __repr__(self):
# here change/refresh val, maybe recalling it
return str(self.executable())
def __eq__(self, other):
#here you compare the new value with another one, it's called when you do val_a == other
if self.executable() == other:
return True
else:
return False
module_b.py
import uuid
from config import var
var_a = var(uuid.uuid4)
print(var_a)
In this way every time you print your var_a
it will change.
But surely the easiest way would be not to store uuid.uuid4()
and simply calling it:
print(uuid.uuid4())
But if you can't do it I think that the class alternative is the best one.
note that using __repr__
will work only if you want the value to be retured as string, else you have to create a new method and call it instead of print
config.py
class var:
def __init__(self, executable):
self.executable = executable
def __eq__(self, other):
#here you compare the new value with another one, it's called when you do val_a == other
if self.executable() == other:
return True
else:
return False
def get(self):
# here change/refresh val, maybe recalling it
return self.executable()
module_b.py
import uuid
from config import var
var_a = var(uuid.uuid4)
print(var.get())