All Questions
7 questions
1
vote
1
answer
813
views
Storing multiple instances on a Singleton?
RefactoringGuru's example Singleton in Python has an _instances dictionary field
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls....
1
vote
2
answers
374
views
Using class attributes as globals in Python - is there a catch?
I have found myself in the habit of using code like this.
class glb:
"just for holding globals"
args = None # from argparse
conf = None # from configparser
def main():
......
4
votes
2
answers
4k
views
What's wrong with using a Singleton?
I'm working on a Python application in which there are two Singleton classes: App and Configuration.
The former seems straight forward, only ever instantiate one App instance; the latter seems ...
-1
votes
1
answer
126
views
How should I represent an object whose instances share the same set of member function identifiers, but those identifiers specify different behaviors?
I'm attempting to develop an open-source Python module for modeling task networks for discrete event simulation. The most fundamental component is the task object, which includes various data such as ...
5
votes
1
answer
12k
views
Using singletons in Python (Django)
I was suggested to define a singleton in Python in the following way:
class Controller:
pass
# ...
controller = Controller()
However, this way, controller cannot be replaced with a derived ...
3
votes
2
answers
2k
views
Is it reasonable to use a decorator to instantiate a singleton in Python?
Suppose I have a class like this:
class Foo(object):
# some code here
As it happens, Foo is a singleton. There are numerous ways to write singletons in Python, but most of them don't really ...
6
votes
1
answer
7k
views
Using module level declared global "singletons" in python
Ok, I know that using singletons is generally a bad practice, but if I do it (for db connection, logging et al.) am I allowed to go (in respect of clean design) with a module defined variable that is ...