class ByRefValue(object): def __init__(self, value): self.value = value
Go where you want, remember that you need to access the value element, not the entire object.
Alternatively, globals().get('a', 0) will return a if it is in the global namespace (or zero if it is missing).
Finally:
import threading tls = threading.local() tls.a = 1
If you import tls into each module where you need it, you will get the same value for a for each thread. Depending on how your program is configured, this may be acceptable, ideal or useless.
source share