Re: A Single Instance of an Object?

2024-03-11 Thread Chris Angelico via Python-list
On Tue, 12 Mar 2024 at 07:54, Ivan "Rambius" Ivanov via Python-list wrote: > I am refactoring some code and I would like to get rid of a global > variable. Here is the outline: > > ... > > I have never done that in Python because I deliberately avoided such > complicated situations up to now. I

Re: A Single Instance of an Object?

2024-03-11 Thread dn via Python-list
Good question Rambius! On 12/03/24 09:53, Ivan "Rambius" Ivanov via Python-list wrote: Hello, I am refactoring some code and I would like to get rid of a global variable. Here is the outline: import subprocess CACHE = {} First thought: don't reinvent-the-wheel, use lru_cache

A Single Instance of an Object?

2024-03-11 Thread Ivan "Rambius" Ivanov via Python-list
Hello, I am refactoring some code and I would like to get rid of a global variable. Here is the outline: import subprocess CACHE = {} def lookup(key): Runs the command cmd, parses its output, extract's the key's value, caches it and returns it. If the key has already been in the

Re: A Single Instance of an Object?

2024-03-11 Thread Ivan "Rambius" Ivanov via Python-list
On Mon, Mar 11, 2024 at 5:01 PM Chris Angelico via Python-list wrote: > > On Tue, 12 Mar 2024 at 07:54, Ivan "Rambius" Ivanov via Python-list > wrote: > > I am refactoring some code and I would like to get rid of a global > > variable. Here is the outline: > > > > ... > > > > I have never done

Re: A Single Instance of an Object?

2024-03-11 Thread Ivan "Rambius" Ivanov via Python-list
On Mon, Mar 11, 2024 at 5:06 PM dn via Python-list wrote: > > Good question Rambius! > > On 12/03/24 09:53, Ivan "Rambius" Ivanov via Python-list wrote: > > Hello, > > > > I am refactoring some code and I would like to get rid of a global > > variable. Here is the outline: > > > > import

Re: Error in Module

2024-03-11 Thread Sanskar Mukeshbhai Joshi via Python-list
Thank you for the information. On Mon, Mar 11, 2024, 22:36 wrote: > Sanskar Mukeshbhai Joshi wrote at 2024-3-10 18:08 +: > >I had made my project in BCA in Python. When I had complete my project > and run the program, at that time I got the error in runnig my project. The > error was

Re: A Single Instance of an Object?

2024-03-11 Thread Chris Angelico via Python-list
On Tue, 12 Mar 2024 at 08:04, Ivan "Rambius" Ivanov wrote: > > A Singleton is just a global variable. Why do this? Did someone tell > > you "global variables are bad, don't use them"? > > I have bad experience with global variables because it is hard to > track what and when modifies them. I

Re: A Single Instance of an Object?

2024-03-11 Thread Peter J. Holzer via Python-list
On 2024-03-11 16:53:00 -0400, Ivan "Rambius" Ivanov via Python-list wrote: > I am refactoring some code and I would like to get rid of a global > variable. Here is the outline: ... > The global cache variable made unit testing of the lookup(key) method > clumsy, because I have to clean it after

Re: Error in Module

2024-03-11 Thread Alan Gauld via Python-list
On 10/03/2024 18:08, Sanskar Mukeshbhai Joshi via Python-list wrote: > I had made my project in BCA in Python. When I had complete my > project and run the program, at that time I got the error in > runnig my project. The error was ModuleNotFoundError: No module named 'flask'. Flask is a third

Error in Module

2024-03-11 Thread Sanskar Mukeshbhai Joshi via Python-list
Respected Sir/Ma'am I had made my project in BCA in Python. When I had complete my project and run the program, at that time I got the error in runnig my project. The error was ModuleNotFoundError: No module named 'flask'. I request you to check this problem and resolve it or guide me to solve

Re: Error in Module

2024-03-11 Thread Dieter Maurer via Python-list
Sanskar Mukeshbhai Joshi wrote at 2024-3-10 18:08 +: >I had made my project in BCA in Python. When I had complete my project and run >the program, at that time I got the error in runnig my project. The error was >ModuleNotFoundError: No module named 'flask'. `flask` is not part of the