encapsulating a global variable

BlindAnagram blindanagram at nowhere.com
Tue Feb 25 12:05:57 EST 2020


On 25/02/2020 16:36, Rhodri James wrote:
> On 25/02/2020 15:20, BlindAnagram wrote:
>>> class GetIt:
>>>    seen = dict()
>>>
>>>    def __call__(self, piece):
>>>      return GetIt.seen[piece]
>>>
>>> get_it = GetIt()
>>>
>>> but then you have a global class instance hanging around, which is not
>>> actually any better than a global dictionary.
>> This doesn't work for me since get_it(piece) returns the error:
>>
>> builtins.TypeError: get_it() takes no arguments
> 
> It works for me (pace sticking something in GetIt.seen to avoid getting
> a KeyError).  You aren't muddling up the class name and instance name
> are you?

Apologies, I misunderstoof your proposal - it woks fine now I have
understood it

  Brian


More information about the Python-list mailing list