help with a com object

Kiss, Arpad AKiss at GEOMETRIA.hu
Wed Aug 30 13:04:12 EDT 2000


Hi,
Next time please attach the traceback too.
Otherwise try to convert the thePath to string before any usage of it. COM
communication uses unicode, but in Python it can cause errors. In your code
os.listdir and "thePath + x" expression generate error messages. Use for
example "os.listdir(str(thePath))" and "os.path.isfile('%s%s' %
(thePath,x))".
Arpad

Scott Hathaway <slhath at home.com.nospam> wrote in message
news:<8G9r5.1195$qO1.72033 at news.flash.net>...
> After trying the following (per the suggestions I have gotten) I get the
> same error.
> 
> class PythonDir:
>  _public_methods_ = [ 'GetListing' ]
>  _reg_progid_ = "PythonDir.Utils"
>  _reg_clsid_ = "{95CBD1B0-7E6F-11D4-AB71-0000929181BF}"
> 
>  def GetListing(self, thePath, theType):
>   import os
>   myFiles = os.listdir(thePath)
>   for x in myFiles :
>    if theType == "f":
>     if os.path.isfile(thePath + x):
>      print x + '|',
>    else:
>     if os.path.isdir(thePath + x):
>      print x + '|',
> 
> if __name__=='__main__':
>  print "Registering COM Server..."
>  import win32com.server.register
>  win32com.server.register.UseCommandLine(PythonDir)
> 
> Please help!
> 
> Scott
> 
> "Arpad Kiss" <sekter at matavnet.hu> wrote in message
> news:004a01c0128b$1b8d67e0$3404a8c0 at geometria.hu...
> > Hi,
> > The methods first parameter is always an instance variable(usually named
> > self).
> > Arpad
> >
> > 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)):
> > >   import os
> > >   myFiles = os.listdir(thePath)
> > >   for x in myFiles :
> > >    if theType == "f":
> > >     if os.path.isfile(thePath + x):
> > >      print x + '|',
> > >    else:
> > >     if os.path.isdir(thePath + x):
> > >      print x + '|',
> > >
> > > if __name__=='__main__':
> > >  print "Registering COM Server..."
> > >  import win32com.server.register
> > >  win32com.server.register.UseCommandLine(PythonDir)
> > >
> > > Here is the php code:
> > >
> > > $pyCOM = new COM("PythonDir.Utils");
> > > $pyCOM->GetListing("c:\\", "f");
> > >
> > > Please help!
> > >
> > > Thanks,
> > > Scott
> > >
> > >
> > > --
> > > http://www.python.org/mailman/listinfo/python-list
> > >
> >
> >
> 
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list