我想用两个字符串之间的句子从我的单词列表开始 以`/结尾。要么 /?或/,或/!
我试过的代码
def sumar():
START = open('F:\\Skripsi\\source code\\katadata.txt', 'r' )
END = "\.|\?"
test = text1.get(0.0, END)
m = re.compile('(%s)(.*?)%s' % (START.read ().replace('\n','|'), END), flags = re.IGNORECASE)
smr = m.search(test).group(2)
se = text2.insert(END, smr)
text1= Text(root, width=50,height=30)
text1.pack(side=LEFT)
text2 = Text(root, width=80, height=30)
text2.pack(side=LEFT)
btn5= Button(root, text= "SUMMARY", command=sumar)
btn5.pack(side=TOP)
但是,当我运行它时,它的错误是这样的:
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1532, in __call__
return self.func(*args)
File "F:\Skripsi\source code\modul-token.py", line 84, in sumar
test = text1.get(0.0, END)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 3074, in get
return self.tk.call(self._w, 'get', index1, index2)
TclError: bad text index "\."
谁能帮助我吗?你好吗
答案 0 :(得分:1)
您已使用END
重新定义了Tk-Constant END = "\.|\?"
。
将您的END
重命名为例如RE_END
。