Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python how to not allow class instance

class BaseClass:    # Py3

    def __new__(cls, *args, **kwargs):
        if cls is BaseClass:
            raise TypeError(f"only children of '{cls.__name__}' may be instantiated")
        return object.__new__(cls, *args, **kwargs)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #class #instance
ADD COMMENT
Topic
Name
1+5 =