[Tutor] string.unprintable?

Neil Schemenauer nas-pytut at python.ca
Fri Nov 21 18:18:25 EST 2003


On Fri, Nov 21, 2003 at 09:24:55PM -0000, Alan Gauld wrote:
> You can either use a nested loop or more usefully a regular 
> expression:
> 
> import re,string
> 
> regex = "[%s]" % string.printable
> 
> printable = re.compile(regex)

You need to escape:

    regex = "[%s]" % re.escape(string.printable)
    
Haven't tested that either though.  Cheers,

  Neil



More information about the Tutor mailing list