Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100976
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Newsgroups | comp.lang.python |
| Subject | Re: Cannot get the value from dogpile.cache from different modules. |
| Date | Tue, 29 Dec 2015 23:30:31 +0000 |
| Lines | 146 |
| Message-ID | <mailman.63.1451431870.11925.python-list@python.org> (permalink) |
| References | <7c8df879-b03a-4323-90c5-3221dd1eced2@googlegroups.com> <e94e9346-cccd-44cb-b889-75c308921555@googlegroups.com> <mailman.55.1451409296.11925.python-list@python.org> <337dc80d-bd55-4976-a716-fc8f793a1322@googlegroups.com> <mailman.59.1451417000.11925.python-list@python.org> <f2a9b5d5-d848-49e8-b5c0-58cfc808f4b0@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de 7PdLk7enw4V1/r+yUDaKsAvWNomeIx8cuJ2/HzXh//tw== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; '"""': 0.05; 'cache': 0.05; 'from:addr:yahoo.co.uk': 0.05; 'badly': 0.07; 'exist,': 0.07; 'problem?': 0.07; 'pypi': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'type)': 0.09; 'stored': 0.10; 'python': 0.10; 'def': 0.13; 'value.': 0.15; '(string)': 0.16; '[1].': 0.16; '[2].': 0.16; 'backend.': 0.16; 'cache:': 0.16; 'dictionary.': 0.16; 'list)': 0.16; 'mailinglist': 0.16; 'modules,': 0.16; 'put.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'utc,': 0.16; 'wrote:': 0.16; 'skip:` 10': 0.18; 'skip:` 20': 0.18; 'creates': 0.18; 'variable': 0.18; 'language': 0.19; '>>>': 0.20; '2015': 0.20; 'java': 0.22; 'lawrence': 0.22; 'file.': 0.22; 'tried': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; '[2]': 0.27; 'subject:skip:d 10': 0.27; 'idea': 0.28; 'values': 0.28; 'dictionary': 0.29; 'end,': 0.29; 'pile': 0.29; 'value)': 0.29; 'you?': 0.30; 'code': 0.30; 'skip:s 30': 0.31; 'december': 0.32; '[1]': 0.32; 'language.': 0.32; 'returned': 0.32; 'class': 0.33; 'url:python': 0.33; 'impression': 0.33; 'file': 0.34; 'list': 0.34; 'could': 0.35; 'saved': 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'there': 0.36; 'url:org': 0.36; 'data.': 0.36; 'skip:m 40': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'doing': 0.38; 'files': 0.38; 'why': 0.39; 'data': 0.39; 'does': 0.39; 'subject:from': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'mark': 0.40; 'save': 0.60; 'your': 0.60; 'show': 0.62; 'charset:windows-1252': 0.62; 'different': 0.63; 'our': 0.64; '>>>>>': 0.66; 'accessed': 0.66; "they're": 0.66; 'here': 0.66; 'subject:get': 0.81; 'pythonistas,': 0.84; 'subject:value': 0.84; 'wheels': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | ip13.worldwideprinting.adsl.gxn.net |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 |
| In-Reply-To | <f2a9b5d5-d848-49e8-b5c0-58cfc808f4b0@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:100976 |
Show key headers only | View raw
On 29/12/2015 22:57, xeon Mailinglist wrote:
> On Tuesday, December 29, 2015 at 7:23:40 PM UTC, Mark Lawrence wrote:
>> On 29/12/2015 17:27, xeon Mailinglist wrote:
>>> On Tuesday, December 29, 2015 at 5:15:24 PM UTC, Mark Lawrence wrote:
>>>> On 29/12/2015 15:20, xeon Mailinglist wrote:
>>>>> 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.
>>>>>
>>>>
>>>> Then put everything in one file. Three files for the amount of code you
>>>> show above is nonsensical. You might like to read
>>>> http://dirtsimple.org/2004/12/python-is-not-java.html and in response to
>>>> that http://dirtsimple.org/2004/12/java-is-not-python-either.html
>>>>
>>>> --
>>>> My fellow Pythonistas, ask not what our language can do for you, ask
>>>> what you can do for our language.
>>>>
>>>> Mark Lawrence
>>>
>>> Here is the full class that I use to store the data.
>>>
>>> from dogpile.cache import make_region
>>>
>>>
>>> # my_dictionary = {}
>>> region = make_region().configure('dogpile.cache.memory')
>>> # arguments={"cache_dict":my_dictionary})
>>> class Cache:
>>>
>>> @staticmethod
>>> 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)
>>>
>>> @staticmethod
>>> 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)
>>>
>>>
>>> @staticmethod
>>> def get_or_create(key):
>>> """
>>> General purpose method to get data from the cache. If the value does not exist, it creates a list
>>>
>>> :param: key (string) key of the data to be fetched
>>> :return value (any type) data to be returned from the cache
>>> """
>>> return region.get_or_create(key, list)
>>>
>>> @staticmethod
>>> def set_job_predictions(rank_list):
>>> Cache.save("job_predictions", rank_list)
>>>
>>> @staticmethod
>>> def get_job_predictions():
>>> return Cache.get("job_predictions")
>>>
>>
>> I get the strong impression that you're reinventing wheels and doing it
>> so badly that they're triangular. Have you tried pypi
>> https://pypi.python.org/pypi for proven code that could do the job for you?
>>
>> --
>> My fellow Pythonistas, ask not what our language can do for you, ask
>> what you can do for our language.
>>
>> Mark Lawrence
>
> @Mark
> I don't understand your remark. Pypi is a repository. What this has to do with my problem?
>
It might well have working code that you can just use, instead of a
dreadful pile of code that has the appalling smell of Java coming out of
every seam.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 03:15 -0800
Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 07:20 -0800
Re: Cannot get the value from dogpile.cache from different modules. Peter Otten <__peter__@web.de> - 2015-12-29 17:17 +0100
Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 09:13 -0800
Re: Cannot get the value from dogpile.cache from different modules. Peter Otten <__peter__@web.de> - 2015-12-29 18:33 +0100
Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 09:38 -0800
Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 10:22 -0800
Re: Cannot get the value from dogpile.cache from different modules. Peter Otten <__peter__@web.de> - 2015-12-29 20:11 +0100
Re: Cannot get the value from dogpile.cache from different modules. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-29 17:14 +0000
Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 09:23 -0800
Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 09:27 -0800
Re: Cannot get the value from dogpile.cache from different modules. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-29 19:22 +0000
Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 14:57 -0800
Re: Cannot get the value from dogpile.cache from different modules. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-29 23:30 +0000
Re: Cannot get the value from dogpile.cache from different modules. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-12-29 17:49 -0500
csiph-web