Re: encapsulating a global variable (BlindAnagram)

2020-02-26 Thread Grant Edwards
On 2020-02-26, Chris Angelico wrote: > On Thu, Feb 27, 2020 at 9:45 AM Grant Edwards > wrote: >> >> On 2020-02-25, Dennis Lee Bieber wrote: >> >> > We seem to have some confusion with the use of the word "static"... >> >> No doubt carrying on the tradition from C, where the 'static' keyword >>

Re: encapsulating a global variable (BlindAnagram)

2020-02-26 Thread Chris Angelico
On Thu, Feb 27, 2020 at 9:45 AM Grant Edwards wrote: > > On 2020-02-25, Dennis Lee Bieber wrote: > > > We seem to have some confusion with the use of the word "static"... > > No doubt carrying on the tradition from C, where the 'static' keyword > is used to mean two completely different, orthogon

Re: encapsulating a global variable (BlindAnagram)

2020-02-26 Thread Grant Edwards
On 2020-02-25, Dennis Lee Bieber wrote: > We seem to have some confusion with the use of the word "static"... No doubt carrying on the tradition from C, where the 'static' keyword is used to mean two completely different, orthogonal things. -- Grant Edwards grant.b.edwards

Re: encapsulating a global variable

2020-02-26 Thread Rhodri James
On 25/02/2020 15:06, BlindAnagram 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. Hiding your dictionary away inside a class or instance isn't going to protect it from threa

Re: encapsulating a global variable

2020-02-25 Thread Greg Ewing
On 26/02/20 3:56 am, BlindAnagram wrote: Does that not have the advantage of preventing the global directory being directly fiddled with elsewhere? That depends on what you mean by "prevent". There is nothing to stop any code from directly accessing the .seen attribute of the class. It might m

Re: encapsulating a global variable

2020-02-25 Thread Greg Ewing
On 26/02/20 4:06 am, BlindAnagram 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. Doing this won't make any difference to the way threaded code behaves. Threading problems ne

Re: encapsulating a global variable (BlindAnagram)

2020-02-25 Thread BlindAnagram
On 25/02/2020 17:16, Christman, Roger Graydon wrote: >> On Tue, 25 Feb 2020 3:06 PM BlindAnagram 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 t

Re: encapsulating a global variable

2020-02-25 Thread Dieter Maurer
BlindAnagram wrote at 2020-2-25 12:38 +: >I would appreciate advice on whether it is possible to avoid the use of >a global variable used in a function by encapsulating it in a class >without maaking any changes to the call interface (which I cannot change). > >I have: > > >seen

Re: encapsulating a global variable (BlindAnagram)

2020-02-25 Thread Christman, Roger Graydon
> On Tue, 25 Feb 2020 3:06 PM BlindAnagram 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

Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
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 >

Re: encapsulating a global variable

2020-02-25 Thread Rhodri James
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 sin

Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
On 25/02/2020 14:14, Rhodri James wrote: > On 25/02/2020 12:38, BlindAnagram wrote: >> I would appreciate advice on whether it is possible to avoid the use of >> a global variable used in a function by encapsulating it in a class >> without maaking any changes to the call interface (which I cannot

Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
On 25/02/2020 14:13, Chris Angelico wrote: > On Wed, Feb 26, 2020 at 12:11 AM BlindAnagram > wrote: >> >> On 25/02/2020 12:56, Chris Angelico wrote: >>> On Tue, Feb 25, 2020 at 11:41 PM BlindAnagram >>> wrote: I would appreciate advice on whether it is possible to avoid the use of >>>

Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
On 25/02/2020 14:14, Rhodri James wrote: > On 25/02/2020 12:38, BlindAnagram wrote: >> I would appreciate advice on whether it is possible to avoid the use of >> a global variable used in a function by encapsulating it in a class >> without maaking any changes to the call interface (which I cannot

Re: encapsulating a global variable

2020-02-25 Thread Rhodri James
On 25/02/2020 12:38, BlindAnagram wrote: I would appreciate advice on whether it is possible to avoid the use of a global variable used in a function by encapsulating it in a class without maaking any changes to the call interface (which I cannot change). I have: seen = dict()

Re: encapsulating a global variable

2020-02-25 Thread Chris Angelico
On Wed, Feb 26, 2020 at 12:11 AM BlindAnagram wrote: > > On 25/02/2020 12:56, Chris Angelico wrote: > > On Tue, Feb 25, 2020 at 11:41 PM BlindAnagram > > wrote: > >> > >> I would appreciate advice on whether it is possible to avoid the use of > >> a global variable used in a function by encapsul

Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
On 25/02/2020 12:50, Musbur wrote: > > Am 25.02.2020 13:38 schrieb BlindAnagram: >> and I am wondering if it is possible to use a class something like >> >> class get_it(object): >> >>   seen = dict() >> >>   def __call__(piece): >>     return seen[piece] > > What happened when you tried it? The

Re: encapsulating a global variable

2020-02-25 Thread BlindAnagram
On 25/02/2020 12:56, Chris Angelico wrote: > On Tue, Feb 25, 2020 at 11:41 PM BlindAnagram > wrote: >> >> I would appreciate advice on whether it is possible to avoid the use of >> a global variable used in a function by encapsulating it in a class >> without maaking any changes to the call inter

Re: encapsulating a global variable

2020-02-25 Thread Musbur
Am 25.02.2020 13:38 schrieb BlindAnagram: and I am wondering if it is possible to use a class something like class get_it(object): seen = dict() def __call__(piece): return seen[piece] What happened when you tried it? -- https://mail.python.org/mailman/listinfo/python-list

Re: encapsulating a global variable

2020-02-25 Thread Chris Angelico
On Tue, Feb 25, 2020 at 11:41 PM BlindAnagram wrote: > > I would appreciate advice on whether it is possible to avoid the use of > a global variable used in a function by encapsulating it in a class > without maaking any changes to the call interface (which I cannot change). Why bother? If you ar