On Tuesday, December 29, 2015 at 11:16:10 AM UTC, xeon Mailinglist wrote: > 1. How do I create a global variable that can be accessed by all classes? > > 2. I am using `dogpile.cache` to store data in the cache [1], but if I set > and get the same key from different modules, I don't get the value. Here is > an example in [2]. The value than I get is `NO_VALUE.NO_VALUE`. Why this > happens? > > setter is the setter.py > getter is the getter.py > Memoize is the file in [1]. > > > [1] my dogpile class `Memoize.py` > > from dogpile.cache import make_region > > region = make_region().configure('dogpile.cache.memory') > > def save(key, value): > """ > general purpose method to save data (value) in the cache > > :param key (string) key of the value to be saved in cache > :param value (any type) the value to be saved > """ > region.set(key, value) > > > def get(key): > """ > general purpose method to get data from the cache > > :param key (string) key of the data to be fetched > :return value (any type) data to be returned from the cache > """ > return region.get(key) > > > [2] My python example > > `setter.py` > > def myset(value): > Memoize.save("myvalue", value) > > `getter.py` > > def myget(): > return Memoize.get("myvalue") <- this value is NO_VALUE. NO_VALUE > > My class: > > setter.myset(123) > getter.myget()
The idea that I get from dogpile, is that in each module (getter.py, or setter.py) there is a dictionary where the values are stored in the backend. Hence, getter.py has its dictionary and setter.py has its dictionary also. In the end, there is not a single dictionary where all the values should be put. And I want a single dictionary. -- https://mail.python.org/mailman/listinfo/python-list