Python COM : Wierd Behaviour

Hafeez Bana hafeez at
Thu May 18 00:52:27 EDT 2000


I have a python object for generating formatted Order documents  which I
have exposed via
COM so that the API could be used by some order taking software written
in Delphi 4. The Python version in use is 1.5.2.

The code has been working fine for a couple of days and then yesterday
it kept on raising the following error. "Unexpected Python Error.
Exception TypeError: too many arguments; expected 1 got 2" on a method
in the object called "printToFile" (which writes out the document to a
specified file name. The actual method declaration is 

  def printToFile(self,py_uni_filename):

The code has been working fine so far. So in an effort to debug it
further (I suspected that some mandatory fields in the document were
being left out which turns out not to be true)  I implemented another
function "def rawPrint(self):" which returns a string representation of
objects field values. This function calls no other simply
returns a string representation of a list via str(self.document_values).
Surprisingly rawPrint fails with the same error as printToFile. I
changed rawPrint to do nothing ie.

  def rawPrint(self):

and even to 

  def rawPrint(self):
      return 1

The same error keeps on being raised "Unexpected Python Error. Exception
TypeError: too many arguments; expected 1 got 2". Even stranger .. the
printToFile method is now working, add an extra function rawPrint seems
to fix other problems!!!

I then changed rawPrint to

   def rawPrint(self, value = 9):
      return 1

and rawPrint calls stops raising the above exception and everything is
working withouth a hitch!!!

I have sample test code written in python and create tried creating the
COM object via win32com.client.Dispatch and
win32com.client.dynaminc.Dispatch but the python test code reports no
errors. Only test code that is written in delphi has this strange

Does anyone have an ideas,suggestions. The code seems to be
temperamental :)


More information about the Python-list mailing list