在处理中文时,isspace
函数可能会遇到问题,因为中文字符不被视为空白字符。解决方法如下:
def is_whitespace(ch):
if ch.isspace() or ord(ch) == 12288 or ord(ch) in range(8192, 8200):
return True
else:
return False
import re
def is_whitespace(ch):
if re.match(r'[\s\u3000]', ch):
return True
else:
return False
使用上述的自定义函数或正则表达式,可以解决isspace
函数对中文处理的问题。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:vc下使用textbackground()函数的问题