About 271,000 results
Open links in new tab
  1. What is the best way of implementing a singleton in Python?

    Jun 10, 2020 · Or in Python 3: class Logger(metaclass=Singleton): pass If you want to run __init__ every time the class is called, add. else: cls._instances[cls].__init__(*args, **kwargs) …

  2. Is there a benefit to defining a class inside another class in Python?

    Sep 17, 2008 · I don't know Python, but your question seems very general. Ignore me if it's specific to Python. Class nesting is all about scope. If you think that one class will only make …

  3. python - How to build a basic iterator? - Stack Overflow

    This question is about iterable objects, not about iterators. In Python, sequences are iterable too so one way to make an iterable class is to make it behave like a sequence, i.e. give it …

  4. Generics/templates in python? - Stack Overflow

    Oct 13, 2014 · Each time you create a generic type, it will create a new type. Thus, multiple classes inheriting List( str ) as a parent would be inheriting from two separate classes. To …

  5. python - Creating class instance properties from a dictionary?

    The above code snippet creates a class of which instance attributes are based on a given dictionary. SilentGhost's code creates a class whose class attributes are based on a given …

  6. Proper way to declare custom exceptions in modern Python?

    Dec 17, 2013 · To create a specific exception, subclass the base exception class. class CustomError(MyProjectError): """A custom exception class for MyProject.""" You can subclass …

  7. oop - How do I implement interfaces in python? - Stack Overflow

    class IncompleteAccountingSystem(AccountingSystem): pass >>> accounting = IncompleteAccountingSystem() Traceback (most recent call last): File "<stdin>", line 1, in …

  8. What's the best way to generate a UML diagram from Python …

    May 3, 2015 · Epydoc is a tool to generate API documentation from Python source code. It also generates UML class diagrams, using Graphviz in fancy ways. Here is an example of diagram …

  9. How to add property to a python class dynamically?

    It's an object that provides custom handling for a given attribute, on a given class. Kinda like a way to factor a huge if tree out of __getattribute__. When I ask for foo.b in the example above, …

  10. python - initialize child class with parent - Stack Overflow

    May 7, 2015 · Create a class method that takes unchanged a and b, changes them, and then applies the class constructor to them -- this would be good for both parent and child. Then …

Refresh