Python Forum
win32 package: self-modifying source code???
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
win32 package: self-modifying source code???
#1
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:
import win32com.client as win32

ad = win32.gencache.EnsureDispatch('Word.Application')
pass
When 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!
Reply


Messages In This Thread
win32 package: self-modifying source code??? - by Orthoducks - Jan-12-2017, 09:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  MPEG DASH Package implementation similar to M3U8 package anantha_narayanan 0 572 Feb-06-2025, 03:55 AM
Last Post: anantha_narayanan
  Algorithm for extracting comments from Python source code Pavel1982 7 2,844 Aug-28-2024, 02:50 AM
Last Post: timothyferriss
  delivery exe without source code py loky62 2 1,151 Apr-04-2024, 05:47 PM
Last Post: loky62
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 19,720 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  Modifying code cheburashka 1 1,967 Dec-13-2021, 01:01 PM
Last Post: Kebap
  No Module found in other directory than source code [SOLVED] AlphaInc 1 3,215 Nov-10-2021, 04:34 PM
Last Post: AlphaInc
  Generating classes diagram from source code Pavel_47 3 7,825 Oct-01-2021, 03:31 AM
Last Post: Lou
  Python library for win32 console commands eldiener 3 4,674 Aug-24-2021, 10:28 PM
Last Post: bowlofred
  How do I open the Source code of a library? JaneTan 1 3,185 Aug-18-2021, 02:12 AM
Last Post: Larz60+
  Win32\ping.exe windows pops up -very annoying... tester_V 9 4,815 Aug-12-2021, 06:54 AM
Last Post: tester_V

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020