Windows Scripting Component weirdness
Keith Farmer
kfarmer at thuban.org
Mon Mar 18 01:23:28 EST 2002
I modified \Python\Lib\site-packages\win32com\test\testPys.sct into
WSCTest.wsc, source below. Running the testPyScriptlet.js code (also below)
seems to reveal that I am unable to set properties on the instantiated
object. No errors are brought up -- the code just behaves as if I never
assigned new values to the properties.
What am I doing wrong, assuming that the WSH is behaving properly?
----------
Keith J. Farmer
kfarmer at thuban.org
http://www.thuban.org
##########
WSCTest.wsc:
<component>
<Registration
Description="Test WSC/Python Object"
ProgID="Thuban.Test.WSCTest"
Version="1"
ClassID="{2eeb6080-cd58-11d1-b81e-00a0240b2fef}">
</Registration>
<public>
<property name=PyProp1>
<get/>
<put>
<parameter name="newValue"/>
</put>
</property>
<property name=PyProp2>
<get/>
<put>
<parameter name="newValue"/>
</put>
</property>
<method name=PyMethod1>
</method>
<method name=PyMethod2>
</method>
</public>
<script language=python>
PyProp1 = "Foo"
PyProp2 = "Bar"
def get_PyProp1():
return PyProp1
def put_PyProp1(newValue):
PyProp1 = newValue
def get_PyProp2():
return PyProp2
def put_PyProp2(newValue):
PyProp2 = newValue
def PyMethod1():
put_PyProp1('Test')
return "PyMethod1 called: PyProp1 should be 'Test'"
def PyMethod2():
return "PyMethod2 called"
</script>
</component>
##########
testPyScriptlet2.js:
function print(msg)
{
WScript.Echo(msg) ;
}
var thisScriptEngine = ScriptEngine() ;
var majorVersion = ScriptEngineMajorVersion() ;
var minorVersion = ScriptEngineMinorVersion() ;
var buildVersion = ScriptEngineBuildVersion() ;
var m = "" ;
WScript.Echo(thisScriptEngine + " Version " + majorVersion + "." +
minorVersion + " Build " + buildVersion) ;
var scriptlet = new ActiveXObject("Thuban.Test.WSCTest") ;
print("Getting PyProp1");
m = scriptlet.PyProp1 ;
print("PyProp1 = " + m) ;
m = scriptlet.PyProp2 ;
print("PyProp2 = " + m) ;
print("PyMethod1() = " + scriptlet.PyMethod1()) ;
m = scriptlet.PyProp1 ;
print("PyProp1 = " + m) ;
print("PyMethod2() = " + scriptlet.PyMethod2()) ;
scriptlet.PyProp2=scriptlet.PyMethod2() ;
m = scriptlet.PyProp2 ;
print("PyProp2 = " + m) ;
More information about the Python-list
mailing list