WSC in python clears method arguments

T Malcolm nt_colonel at hotmail.com
Fri Nov 9 15:23:28 EST 2001


"Steve Holden" <sholden at holdenweb.com> wrote in message news:<AAzG7.93$qf.16500 at atlpnn01.usenetserver.com>...
> "T Malcolm" <nt_colonel at hotmail.com> wrote ...
> > I'm calling a WSC written in Python from a VBS script that is task
> > scheduled.  This WSC is a "friendly" interface to the Python ftp
> > library.  All is well, except for one quirk.  When I call methods on
> > the WSC, it will clear the variable I pass as an argument.
> >
> So the scripting component is an object, and you are creating instances...
> 
> >
> > Example vbs client script(where objFTP is an instance of the Python
> > WSC):
> > ----
> > strRemotePath = rs.Fields("RemotePath").Value
> >
> > 'strRemotePath has a value here
> >
> > objFTP.cwd(strRemotePath)
> 
> So here you appear to be calling a method of the instance you created...
> >
> > 'strRemotePath is now a nullstring, the cwd command has succeeded.
> > ----
> >
> > Python code in WSC (objFTP is an instance of FTP imported from
> > ftplib):
> > ----
> > def cwd(RemotePath, FTP=objFTP):
> >     FTP.cwd(RemotePath)
> > ----
> 
> But this appears to be a function definition, not a method. Surely cwd()
> shouod be defined inside the definition of the class instantiated as objFTP.
> Its first argument should be self -- that's how ytou'd expect to [pick up
> the object on which the method is being called.
> >
> > I had to use the FTP=objFTP as an argument because I couldn't
> > reference objFTP in the function from the "global" namespace where it
> > resides (another quirk?).
> >
> Erm, objFTP shouldn't (and probably doesn't) reside in your Python module's
> namespace. It should be created dynamically and referred to as self (method
> 1st argument) when required.
> 
> > Anyway, does anybody have any idea how I can get this thing to quit
> > "eating" my variable values?
> 
> There's probably something I'm missing here. Have you got a copy of Hammond
> and Robinson's "Programming Python on Win32"?  Great reference to all this
> stuff.
> 
> regards
>  Steve


Well, see, the COM Component isn't a pure Python module.
All of my Python is in a Windows Script Component(WSC)...an xml file
parsed by the ActiveX Scripting engine.  Classes are set off with
<component></component> tags, and the COM interface is also described
using XML tags.  Since this isn't a proper python class there's no
"self" first argument on the methods, thus causing half of my
problems.  Everything calls, and it works just great, but it eats the
values stored in my argument variables.



More information about the Python-list mailing list