encapsulating a global variable
Rhodri James
rhodri at kynesim.co.uk
Tue Feb 25 11:36:18 EST 2020
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?
--
Rhodri James *-* Kynesim Ltd
More information about the Python-list
mailing list