0
我在嘗試理解ironpython範圍規則時遇到了很大的麻煩。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
問題
打印 「值:」 +數據
值:[] < < < ========不值
我不太明白你的問題,你把結果保存在一個全局變量中。結果是全球數據,也是全球結果。這就是你需要知道的全部內容嗎? :) – Skurmedel 2011-02-15 13:20:59
你的問題沒有意義。更何況你有幾個縮進錯誤。 – delnan 2011-02-15 13:33:53