bnmcvzx 2020-05-03
方法一: 正则
>>> 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)
原文详见: