non printable (moving away from Perl)

Marko Rauhamaa marko at pacujo.net
Fri Mar 11 07:47:33 EST 2016


Wolfgang Maier <wolfgang.maier at biologie.uni-freiburg.de>:

> On 11.03.2016 13:13, Wolfgang Maier wrote:
>> One lesson for Perl regex users is that in Python many things can be
>> solved without regexes. How about defining:
>>
>> printable = {chr(n) for n in range(32, 127)}
>>
>> then using:
>>
>> if (set(my_string) - set(printable)):
>>      break
>>
>
> Err, I meant:
>
> if (set(my_string) - printable):
>     break
>
> of course. No need to attempt another set conversion.

Most non-ASCII characters are printable, or at least a good many.

Unfortunately, "printable" doesn't seem to be a Unicode category.


Marko



More information about the Python-list mailing list