I am working on replacing a value of a TextCtrl(name:control) from another TextCtrl(name:controlz). I have done that so far.
def replace(self, event):
newtext = tokenize_editor_text(self.controlz.GetValue())
text = tokenize_editor_text(self.control.GetValue())
for word in text:
if (word == misspelled_list[0]):
text[text.index(word)] = newtext
corrected = ' '.join(map(str,text))
self.control.SetValue(corrected)
print corrected
for example when there is an input( Chony)
in (self.controlz)
and to replace another word (choni)
in (self.control)
it replaces [u'chony']
. even I have used ' '.join(map(str,text))
.How can I get the same value ( chony ) not [u'chony']
any solution appreciated.
Many thanks
答案 0 :(得分:0)
如果您在列表或元组上调用str
,则会显示列表内部值的repr
str(["1","2"]) #==> '[u"1",u"2"]'
此次电话
newtext = tokenize_editor_text(self.controlz.GetValue())
返回一个我相信[u"chony"]
然后将该列表值设置为
中的列表索引text[i] = newtext #==> text[i] = [u"chony",] ... => text = [[u"chony"],[...]]
稍后您调用每个文本项的字符串
map(str, text) # which calls str on the array that you set as the indexes
如果newtext
中只有一个元素,则可以只分配第0个索引
text[i] = newtext[0]