Basic Idea
In python all the default, or inbuild dunder methods are called by specific function. For example, the __next__
is called by next()
, __len__
is called by len()
, ... etc. So when we make a custom dunder method I suggest you to make a function that can call the dunder method.
The code
# lets first make a function that will call a the logging method
# the function accepts an argument which is a class that is assumed to have a
# __logging__ method.
def logging(cls):
return cls.__logging__()
class Cls:
def __logging__(self):
return "logging called"
# you can use this method by this code
cls = Cls()
print(logging(cls)) # output => logging called
# or if you don't have a function to call the dunder method
# you can use this
cls = Cls()
print(cls.__logging__()) # output => logging called