My missing posts

Mark Hammond mhammond at skippinet.com.au
Tue Oct 12 22:53:57 EDT 1999


> Actually about a month ago, you sent me e-mail saying that
> you had posted
> code that would make it possible to use win32com without
> having to use the
> registry and that I could find it using DejaNews.  I was
> unable to find it
> (I thought because of my own incompetence) so if you have it handy
I'd
> appreciate a re-post.

Actually, the post I am referring to was about 6 months ago (which
still doesnt mean it made it :-(.  Here it is again:

Mark.
import win32api, imp, sys

def magic_import(modulename, filename):
	# win32 can find the DLL name.
	h = win32api.LoadLibrary(filename)
	found = win32api.GetModuleFileName(h)
	# Python can load the module
	mod = imp.load_module(modulename, None, found, ('.dll', 'rb',
imp.C_EXTENSION))
	# inject it into the global module list.
	sys.modules[modulename] = mod
	# And finally inject it into the namespace.
	globals()[modulename] = mod
	win32api.FreeLibrary(h)

try:
	import pywintypes
except ImportError:
	magic_import("pywintypes", "pywintypes15.dll")
try:
	import pythoncom
except ImportError:
	magic_import("pythoncom", "pythoncom15.dll")





More information about the Python-list mailing list