2013-07-09 22 views
-2

我試圖做一個瞬移模塊一場比賽,但是首先我必須從ListBoxExPython的正則表達式:關於獲取文本

self.Gui[3].AppendItem(Item(str(chr.GetNameByVID(i)) + " " + str(nonplayer.GetLevelByVID(i)) + " " + "%d, %d" % (mobX/100, mobY/100))) 

http://i.stack.imgur.com/MX8aV.jpg

得到座標我想這

mob_x, mob_y = re.findall(r"\(([0-9]+), ([0-9]+)\)", item_index.GetText())[0] 

結果:索引錯誤

def Teleport(self): 
    item_index = self.Gui[3].GetSelectedItem() 
    if not item_index: 
     chat.AppendChat(chat.CHAT_TYPE_INFO, "Kein Item ausgewählt!") 
     return 
    mob_x, mob_y = re.findall(r"\(([0-9]+), ([0-9]+)\)", item_index.GetText())[0] 

    chr.SetPixelPosition(mob_x, mob_y) 
+1

請問您可以複製一個您想用正則表達式解析的文本樣本嗎? – mariosangiorgio

+0

索引錯誤意味着你得到一個空列表,即它沒有匹配任何東西。 –

+0

你可能已經編輯了你以前的問題。 – IcyFlame

回答

0

根據屏幕截圖,您的文本類似於「108,109」,但是請求表達式正在解析「(108,109)」。使用:

mob_x, mob_y = re.findall(r"([0-9]+), ([0-9]+)", item_index.GetText())[0] 
+0

非常感謝你現在的工作**你的老闆:D – user2563164