开发者

Global variables in Ironpython

I'm having terrible trouble trying to understand ironpython scoping rules.

With the following script:


global data
// function for call xml-rpc 
def CallListDatabases(self):
    global synC, synCtx, result, data   
        self.synCtx = synC.Current
        service = XmlRpcService("http://localhost:8000/rpc")
        req = XmlRpcRequest(service, 'vocab_list')
        req.XmlRpcCallCompleteHandler += self.req_XmlRpcCallCompleteHandler
        result = req.Execute(self)

//if call xml-rpc complete then use working rpc 
def req_XmlRpcCallCompleteHandler (self, response, userState):
    global synCtx, synC, data
        word = []
        f = response.TryCast(clr.GetClrType(Fault))
        if f != None:
 开发者_如何学JAVA           self.synCtx.Post(self.SetCallResult, f)
            if f.FaultCode == -1:
                pass
        else:
            self.synCtx.Post(self.SetCallResult, response)

// show result with rpc complete
def SetCallResult(self, userState):
        global data, result                
        if userState.GetType() == clr.GetClrType(Fault):
            f = userState
            if f != None:
                print str(f.FaultString)
                return    
        response = userState
        result = response.TryCast(clr.GetClrType(Array[str]))
        data = result   //I want to use value it

print "value: "+data  //show value     

Problem

print "value: "+data


value: [] <<<======== Not value


First of all, you don't seem to ever be calling any of the functions you have defined. If you are calling the functions, it appears that the return value of response.TryCast(clr.GetClrType(Array[str])) is an empty list. Have you tried printing the value of result within SetCallResult()? I'd bet that it's [].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜