Python 官方文档:入门教程 => 点击学习
使用 xlrd 模块打开带中文的excel文件时,会报错。FileNotFoundError: [Errno 2] No such file or direct
使用 xlrd 模块打开带中文的excel文件时,会报错。
FileNotFoundError: [Errno 2] No such file or directory: 'xx.xlsx'
这个时候,就需要检测文件名,是否包含中文,及时return。
中文字符的编码范围是:
\u4e00 - \u9fff
只要编码在此范围就可判断为中文字符
def is_chinese(self, string):
"""
检查整个字符串是否包含中文
:param string: 需要检查的字符串
:return: bool
"""
for ch in string:
if u'\u4e00' <= ch <= u'\u9fff':
return True
return True
本文参考链接:
https://segmentfault.com/a/1190000017940752?utm_source=tag-newest
--结束END--
本文标题: Python 判断字符串是否包含中文
本文链接: https://www.lsjlt.com/news/193573.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0