一、摘要

使用 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

Python 判断字符串是否包含中文的更多相关文章

  1. python判断字符串是否包含子字符串

    python的string对象没有contains方法,不可以使用string.contains的方法判断是否包含子字符串,但是python有更简单的方法来替换contains函数 python的st ...

  2. python 判断字符串是否包含子字符串

    第一种方法:in string = 'helloworld' if 'world' in string: print 'Exist' else: print 'Not exist' 第二种方法:fin ...

  3. Java 编程下正则表达式判断字符串是否包含中文

    package cn.sunzn.demo; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ...

  4. Oracle PLSQL Demo - 22.查看字符串的长度[lengthb, length],判断字符串是否包含中文

    --Count the length of string select lengthb('select * from scott.emp') as countted_by_byte, length(' ...

  5. python 判断字符串中是否只有中文字符

    python 判断字符串中是否只有中文字符 学习了:https://segmentfault.com/q/1010000007898150 def is_all_zh(s): for c in s: ...

  6. python判断字符串中是否包含子字符串

    python判断字符串中是否包含子字符串 s = '1234问沃尔沃434' if s.find('沃尔沃') != -1:     print('存在') else:     print('不存在' ...

  7. PHP判断字符串的包含

    PHP语言是一个功能强大的嵌入式HTML脚本语言,它的易用性让许多程序员选择使用.PHP判断字符串的包含,可以使用PHP的内置函数strstr,strpos,stristr直接进行判断.也可以通过ex ...

  8. Python判断字符串编码以及编码的转换

    转自:http://www.cnblogs.com/zhanhg/p/4392089.html Python判断字符串编码以及编码的转换 判断字符串编码: 使用 chardet 可以很方便的实现字符串 ...

  9. Java检查字符串是否包含中文字符

    转自:https://blog.csdn.net/zhanghan18333611647/article/details/80038629 强烈推荐一个大神的人工智能的教程:http://www.ca ...

随机推荐

  1. 微信小程序HTTP封装请求

    http.js import utils from "../../utils/utils" var http = utils.http; const douban = " ...

  2. 在GitHub上使用Hexo 搭建自己的博客

    1.下载Node.js安装文件(现在电脑基本都是64位的,我就放64位的下载地址):https://nodejs.org/dist/v8.9.4/node-v8.9.4-x64.msi 或者自行到官网 ...

  3. 解决WordPress访问中文标签出现404的几个方法

    最近很多主题用户提到安装完WordPress后中文标签出现404的情况,出现这种情况一般修改固定链接设置是没有效果的,多数是windows主机带来的麻烦.网上多数人说要修改核心文件class-wp.p ...

  4. spring boot后端使用fastjson,错误代码415, 500

    $.post({ url: "/register", dataType: "json", contentType: "application/json ...

  5. pdfBox 解析 pdf文件

    Spting boot 项目 1.添加依赖 <dependency> <groupId>org.apache.pdfbox</groupId> <artifa ...

  6. MYSQL 什么时候用单列索引?什么使用用联合索引?

    我一个表 students 表,有3个字段 ,id,name,age 我要查询 通过 name 和age,在这两个字段 是创建 联合索引?还是分别在name和age上创建 单列索引呢? 多个字段查询什 ...

  7. Windows安装pip、wxpy

    版权归作者所有,任何形式转载请联系作者.作者:为什么不是学霸(来自豆瓣)来源:https://www.douban.com/note/696046743/ # 适用于0基础 1.安装好python. ...

  8. [Bayes] Concept Search and LDA

    重要的是通过实践更深入地了解贝叶斯思想,先浅浅地了解下LDA. 相关数学知识 LDA-math-MCMC 和 Gibbs Sampling LDA-math - 认识 Beta/Dirichlet 分 ...

  9. plsql 的三种循环

    set serveroutput on declare pnum ; begin loop dbms_output.put_line(pnum); pnum :; end loop; end; / s ...

  10. [LeetCode] 312. Burst Balloons 爆气球

    Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by ...