A PythonCOM tidbit

greg Landrum gReGlAnDrUm at earthlink.net
Wed Feb 14 00:09:37 EST 2001


This is probably abundantly clear to everyone who actually thinks hard
about pythonCOM, but I just ran into problems with it, so I figure I'll
point it out...

I was feeling particularly uncreative whilst creating the names of my
source files for COM servers.  So I had two different COM servers Foo.Obj
and Bar.Obj implemented in files called COMServer.py (yeah, yeah, I was
*asking* for it) which lived in different directories (Foo and Bar).  These
were both registered and worked just fine.

Until I tried to use them in succession on Excel. Then I started getting
AttributeErrors.  I'd create an instance of Foo.Obj, work with it for a
bit, then try and create an instance of Bar.Obj.  BAM! AttributeError for
BarServer (the class defining Bar.Obj).  Or I could work with Bar.Obj for a
while and then try creating a Foo.Obj.  Instant AttributeError for
FooServer (the class defining Foo.Obj).

After spending a while trying to figure out what the heck was going on,
frantically flipping through PPW32 (once again: kudos to Mark and Andy for
this fantastic tome), and generally getting all worked up, it hit me... 
when I first create a Foo.Obj, pythoncom is importing a module called
COMServer from directory Foo. Later, when I try to create Bar.Obj,
pythoncom tries to import COMServer, but it must see that a module called
COMServer is already loaded, so it doesn't load the new one.

The solution to this problem is, of course, to not use names quite so
stupid as COMServer.

-greg



More information about the Python-list mailing list