encapsulating a global variable (BlindAnagram)

BlindAnagram blindanagram at nowhere.com
Tue Feb 25 13:10:37 EST 2020


On 25/02/2020 17:16, Christman, Roger Graydon wrote:
>> On Tue, 25 Feb 2020 3:06 PM BlindAnagram <blindanagram at nowhere.com> wrote:
> 
>> My interest in this stems from wanting to keep the dictionary only
>> available to the function that uses it and also a worry about being
>> called from threaded code.
> 
> It seems like the simplest solution for this is to make
> a completely new file (module) containing nothing but
> the dictionary and this one function that uses it.
> Then you can import the function from the module
> wherever it is called without importing the dictionary.
> 
> The thing I find curious is that apparently no other
> function is allowed to create or populate the dictionary
> in the first place.   Is it practical to have the entire
> dictionary statically defined?

The dictionary is a static variable of the function. It is updated by
the function and must maintain values across function calls.

Reading some more, it seems that I can create static function variables
using attributes.

  Brian


More information about the Python-list mailing list