Jul-01-2020, 05:34 AM
import io class YourObject(io.IOBase): def __init__(self): self.value = 'this value' def some_method(self): return 'some_method' def __getattribute__(self, name): print(f'attribute {name}') return object.__getattribute__(self, name) your_instance = YourObject() print(your_instance.value) print(your_instance.some_method()) print('finished with YourObject')
Output:attribute value
this value
attribute some_method
some_method
finished with YourObject
attribute closed
attribute __IOBase_closed
attribute close
attribute __IOBase_closed
attribute flush
attribute __IOBase_closed
Accessing attributes does not happen recursively in the above codeThe following are called when the class is done with
Output:attribute closed
attribute __IOBase_closed
attribute close
attribute __IOBase_closed
attribute flush
attribute __IOBase_closed