> Hi folks. > > Earlier messages suggested a nice singleton decorator, which is shown > in the draft PEP: [...] > But i don't think this is a good way to write a singleton, because then > the user of the class has to get instances by saying "MyClass" instead > of "MyClass()". Depending on how you look at it, that might be a good thing. In particular, it "documents" the fact that you're using a singleton, which might make your code easier to read/understand. (You expect very different behavior from a singleton than from a normal class). On a related note, now that Python has class methods, is there much point in a "singleton" pattern? In particular, why not just make a class that only defines class methods, and uses the class namespace to store variables (instead of an instance namespace)? -Edward
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4