C's isprint() concept?

Tim Peters tim_one at email.msn.com
Sun Aug 15 22:31:18 EDT 1999


[Jeff Blaine, wants to
> ... replace all non-printable characters in a string
> with a single space

[Aahz Maruch]
> Oh, sure.  What isn't clear from the way you write this is whether
> a run of multiple non-printable characters should be replace with
> a single space.  Here's a regex that I created recently as part of
> some code to detect binary documents:
>
>    # Everything that isn't CR/LF or 7-bit normal characters
>    reBinary = re.compile ( r'[^\r\n\x20-\x7F]' )

Take a look at string.translate.

> ...
> Don't remember offhand what isgraph() does, but it occurs to me that
> it would be useful to have a character class string.printable.
> Tim?  Guido?

I can't speak for Tim, but Guido would say "be my guest -- define whatever
character classes you want".  I think he doesn't want to pee away time
arguing over e.g. whether \x7F is "normal" or not <wink>.

unicode-is-gonna-be-sooooo-much-fun-ly y'rs  - tim






More information about the Python-list mailing list