help with a com object

Alex Martelli aleaxit at yahoo.com
Wed Aug 30 10:12:38 EDT 2000


"Scott Hathaway" <slhath at home.com.nospam> wrote in message
news:E_7r5.914$qO1.64948 at news.flash.net...
> Hello All,
>
> I am trying to create a COM object in python to use with PHP 4.  I have
> listed the entire code below.  All I want it to do is have one method that
> is passed a directory to scan and a flag that tells to return subfolders
or
> files.  From PHP, I can instantiate the COM object without errors, but it
> fails with an exception on the call to GetListing.
>
> class PythonDir:
>  _public_methods_ = [ 'GetListing' ]
>  _reg_progid_ = "PythonDir.Utils"
>  _reg_clsid_ = "{95CBD1B0-7E6F-11D4-AB71-0000929181BF}"
>
>  def GetListing(str(thePath), str(theType)):

I'm surprised this compiles at all for you.  It's
not valid Python syntax; don't you get a syntax error
when trying this out...?

Change the method definition header line to:

    def GetListing(self, thePath, theType):

You need a first argument representing the instance
on which the method is called, and it's common to call
that first argument 'self'.  And no 'str(foo)' in
the arguments' names -- just the names themselves.

If you need to convert an argument to a string, then
do something like
    thePath=str(thePath)
explicitly at the start of the method.


Alex






More information about the Python-list mailing list