Here is the code, it basically uses a win32com instance and gets the attribute and sets the attribute. More methods will be added to this class later.
import win32com.client
class WORD(object):
def __init__(self):
self.word = win32com.client.Dispatch("Word.Application")
def __getattr__(self, val):
try:
print(1)
attr = getattr(self.word, val)
except:
print(2)
attr = super().__getattr__(val)
return attr
def __setattr__(self, attr, val):
try:
print(3)
setattr(self.word, attr, val)
except:
print(4)
super().__setattr__(attr, val)
app = WORD()
It outputs 2 for 635 times and a 4 at the end. Why? Thank you.
2
2
2
2
2
2
2
2
2
2
.
.
.
2
2
2
2
2
2
2
2
2
4