I have a class Log
and I want to create another class NullLog
which has all the same method names as Log
, but all of its methods are set to the function do_nothing()
. That way I can use a NullLog
object in place of a Log
object to prevent anything from being logged, without any errors occurring from methods that don’t exist being called.
I could use inspect.getmembers()
as shown here to get all the methods in Log
, then use exec()
to assign methods with the same names on initialisation of a NullLog
object, but it seems like there should be a better way.
4