Jul-21-2021, 06:39 AM
Skaperen Wrote:the objective is to return an instance of file class instead of an instance of itselfI'm not sure I understand what you are trying to do but calling a class' constructor to get an object of a different type seems completely inappropriate. More specifically,
__init__()
methods don't even use the return statement in Python.You could achieve the same (misleading) effect by overwriting the name of the class
class Foo: pass class Bar: pass _c_foo = Foo def Foo(condition): if condition: return _c_foo() else: return Bar() if __name__ == '__main__': f = Foo(0) # returns a Bar instance while pretending to create a Foo instance.