Is there a python construct corresponding to a function taking no arguments, doing nothing and not returning anything? Something similar to a None object, but will it be a function instead of an object?
Context
I want to define a class in which the constructor receives the function as an argument and refers to the class attribute. After the expiration, the user decides whether he wants this function to be the actual function that he defines, or to leave the default value, which should call a dummy function that does nothing.
Here is what I have now:
def sayHello(): print("hello world !") def doNothing(): pass class myClass: def __init__(self, myFunc): self.doIt = myFunc myInstance = myClass(sayHello) myInstance.doIt() myInstance = myClass(doNothing)
source share