Ironpython 中的全局变量

发布于 2024-10-17 14:42:44 字数 1458 浏览 7 评论 0原文

我在尝试理解 IronPython 范围规则时遇到了很大的麻烦。

使用以下脚本:


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:
            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     

问题
print "值: "+数据


值: [] <<<======不是值

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:
            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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜深人未静 2024-10-24 14:42:44

首先,您似乎从未调用过您定义的任何函数。如果您调用这些函数,则 response.TryCast(clr.GetClrType(Array[str])) 的返回值似乎是一个空列表。您是否尝试过在 SetCallResult()打印结果的值?我敢打赌它是[]

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 [].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文