Have managed to get by the CoInitialize problem using COM with Zope in an external method. The method has been tested in straight python 1.52 and works great there. Now I need some help. Here is the traceback: ---------------------------------------------------------------------- ... Error type: AttributeError Error value: GetModuleForCLSID ... Traceback (innermost last): File C:\Program Files\AtiAnywhere\lib\python\ZPublisher\Publish.py, line 214, in publish_module File C:\Program Files\AtiAnywhere\lib\python\ZPublisher\Publish.py, line 179, in publish File C:\Program Files\AtiAnywhere\lib\python\Zope\__init__.py, line 202, in zpublisher_exception_hook (Object: ElementWithAttributes) File C:\Program Files\AtiAnywhere\lib\python\ZPublisher\Publish.py, line 165, in publish File C:\Program Files\AtiAnywhere\lib\python\ZPublisher\mapply.py, line 160, in mapply (Object: AWordTest) File C:\Program Files\AtiAnywhere\lib\python\ZPublisher\Publish.py, line 102, in call_object (Object: AWordTest) File C:\Program Files\AtiAnywhere\lib\python\OFS\DTMLMethod.py, line 145, in __call__ (Object: AWordTest) File C:\Program Files\AtiAnywhere\lib\python\DocumentTemplate\DT_String.py, line 502, in __call__ (Object: AWordTest) File C:\Program Files\AtiAnywhere\lib\python\DocumentTemplate\DT_Let.py, line 145, in render (Object: TFile="r'q:\atidb\users\u\wwwTestTmplt.doc'" RFile="r'q:\atidb\users\u\Test19.doc'" RList="[['<Firstname>','Duanne'],['<LastName>','Jones']]") File C:\Program Files\AtiAnywhere\lib\python\DocumentTemplate\DT_Util.py, line 335, in eval (Object: WReplace(TFile,RFile,RList)) (Info: RList) File <string>, line 0, in ? File C:\Program Files\AtiAnywhere\lib\python\Products\ExternalMethod\ExternalMethod.py, line 248, in __call__ (Object: WReplace) (Info: (('q:\\atidb\\users\\u\\wwwTestTmplt.doc', 'q:\\atidb\\users\\u\\Test19.doc', [['<Firstname>', 'Duanne'], ['<LastName>', 'Jones']]), {}, None)) File C:\Program Files\AtiAnywhere\Extensions\WordR.py, line 32, in WordReplace File C:\Program Files\AtiAnywhere\Extensions\WordR.py, line 23, in formletter File C:\Program Files\AtiAnywhere\Extensions\WordR.py, line 9, in __init__ File C:\Program Files\Python\win32com\client\__init__.py, line 28, in Dispatch AttributeError: (see above) ----------------------------------------------------------------------------- WordR is reproduced below. It works fine in regular Python: import os, sys, pickle from client import constants, Dispatch WORD = 'Word.Application.8' False, True = 0, -1 import string class Word: def __init__(self): self.app = Dispatch(WORD) def open(self, doc): self.app.Documents.Open(FileName=doc) def replace(self, source, target): find = self.app.Selection.Find find.Text = source self.app.Selection.Find.Execute() self.app.Selection.TypeText(Text=target) def printdoc(self): self.app.Application.PrintOut() def close(self): self.app.ActiveDocument.Close(SaveChanges=True) def formletter(doc,rplctuple): word = Word() word.open(doc) for x in rplclist: word.replace(x[0],x[1]) word.close() def WordReplace(TmpltFile,ReplaceFile,ReplaceList): from shutil import copyfile copyfile(TmpltFile,ReplaceFile) formletter(ReplaceFile,ReplaceList) # WordReplace(r"q:\atidb\users\u\wwwTestTmplt.doc", r"q:\atidb\users\u\Test10.doc", [['<FirstName>','Jim'],['<LastName>','Sanford']])
On Tue, 11 Apr 2000 18:02:03 -0500, "Jim Sanford" <jsanford@atinucleus.com> wrote:
Have managed to get by the CoInitialize problem using COM with Zope in an external method.
OK. Are you calling CoInitializeEx(COINIT_MULTITHREADED)? If not you may be in for some subtle bugs. However, I don't think thats the cause of this.
Error type: AttributeError Error value: GetModuleForCLSID .....snip the boring bit of the traceback File C:\Program Files\AtiAnywhere\Extensions\WordR.py, line 23, in formletter File C:\Program Files\AtiAnywhere\Extensions\WordR.py, line 9, in __init__ File C:\Program Files\Python\win32com\client\__init__.py, line 28, in Dispatch AttributeError: (see above)
Thats very strange. Lines around 28 of __init__ are... try: import gencache if gencache.GetModuleForCLSID(resultCLSID) is not None: And the module gencache definitely includes GetModuleForCLSID, so that doesn't explain the AttributeError. Can I suggest you change this to.... try: import gencache raise 'eh?', (gencache,dir(gencache)) if gencache.GetModuleForCLSID(resultCLSID) is not None: That should tell you exactly what gencache is, and what symbols it contains. Hopefully that should be a hint to the real problem. (ps. Then remove that line when you are done, or youll find all your other pythoncom scripts are broken ;-) Toby Dickenson tdickenson@geminidataloggers.com
participants (2)
-
Jim Sanford -
Toby Dickenson