Python 判断字符串书否是纯ASCII (printable)
2021-01-30 14:14
标签:python set search 判断 you ref sprint str ons 方法一: 正则 方法二: 原文详见: Test if a python string is printable Python 判断字符串书否是纯ASCII (printable) 标签:python set search 判断 you ref sprint str ons 原文地址:https://www.cnblogs.com/yunqimg/p/ascii-printable.html>>> import re
>>> # Printable
>>> print re.search(r‘[^\x20-\x7e]‘, ‘test‘)
None
>>> # Unprintable
>>> re.search(r‘[^\x20-\x7e]‘, ‘test\x00‘) != None
True
import string
printset = set(string.printable)
isprintable = set(yourstring).issubset(printset)
文章标题:Python 判断字符串书否是纯ASCII (printable)
文章链接:http://soscw.com/essay/49130.html