I'm trying to use win32 to edit Microsoft Word documents in Python code. So far I've got this, gleaned from various examples on the web:
I've got a couple of questions about this. First, assuming I understand what's happening, why is it OK? Self-modifying code compromises security and maintainability; I haven't seen it done since the '80s, and even then it was only done in RAM. I never dreamed I'd encounter software that modifies its own source code just to initialize.
The second question is: how is it supposed to work? Shared Python packages are installed in the Python program directory, which (in Windows) is in one of the Program Files directories. Of course my program gets a permission error; it isn't allowed to modify program files without administrative privilege, and it darned well shouldn't!
import win32com.client as win32 ad = win32.gencache.EnsureDispatch('Word.Application') passWhen I run it I get a couple of dozen lines of errors, ending with:
Error:f = open(fname,"w")
...Permission denied: 'C:\\...\\Python 3.5\\lib\\site-packages\\win32com\\gen_py\\__init__.py'
I don't understand a lot of the messages, but it appears that win32com.client gets an error because the gencache object isn't defined, then gets a permission error trying to define the object by changing its own source code.I've got a couple of questions about this. First, assuming I understand what's happening, why is it OK? Self-modifying code compromises security and maintainability; I haven't seen it done since the '80s, and even then it was only done in RAM. I never dreamed I'd encounter software that modifies its own source code just to initialize.
The second question is: how is it supposed to work? Shared Python packages are installed in the Python program directory, which (in Windows) is in one of the Program Files directories. Of course my program gets a permission error; it isn't allowed to modify program files without administrative privilege, and it darned well shouldn't!