Quantcast
Channel: Stripping non printable characters from a string in python - Stack Overflow
Viewing all articles
Browse latest Browse all 17

Stripping non printable characters from a string in python

$
0
0

I use to run

$s =~ s/[^[:print:]]//g;

on Perl to get rid of non printable characters.

In Python there's no POSIX regex classes, and I can't write [:print:] having it mean what I want. I know of no way in Python to detect if a character is printable or not.

What would you do?

EDIT: It has to support Unicode characters as well. The string.printable way will happily strip them out of the output. curses.ascii.isprint will return false for any unicode character.


Viewing all articles
Browse latest Browse all 17

Latest Images

Trending Articles





Latest Images