Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

Patrick Maupin pmaupin at gmail.com
Mon Oct 31 20:32:34 EDT 2011


On Mon, Oct 31, 2011 at 4:08 PM, Dave Angel <d... at davea.name> wrote:

Yes.  Actually, you don't even need the split() -- you can pass an
optional deletechars parameter to translate().


On Oct 31, 5:52 pm, Ian Kelly <ian.g.ke... at gmail.com> wrote:

> That sounds overly complicated and error-prone.

Not really.

> For instance, split() will split on vertical tab,
> which is not one of the characters the OP wanted.

That's just the default behavior.  You can explicitly specify the
separator to split on.  But it's probably more efficient to just use
translate with deletechars.

> I would probably use a regular expression for this.

I use 'em all the time, but not for stuff this simple.

Regards,
Pat



More information about the Python-list mailing list