[英]How to fix “IndexError: string index out of range” error in python
[英]Contraction.fix resulted an error "IndexError: string index out of range"
我正在将contracts.fix应用于文本,但在将try catch块应用于文本后导致错误“IndexError:字符串索引超出范围”我设法发现它在两个特定单词中抛出错误。
%%time
import re
import contractions
import unicodedata
text = our_text
expanded_words = []
for word in text.split():
try:
expanded_words.append(contractions.fix(word))
except:
print(word,len(word))
Output:
伊特布努 7
伊莱蒂西姆 8
contractions.fix('İtburnu')
output:“IndexError:字符串索引超出范围”
为什么这两个特定的词会导致错误?
这是 UTF-8 字符问题。
如果你试试
宫缩.fix('Itburnu')
和
收缩。修复('Iletisim')
你会得到 output。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.