[Tutor] Checking for Control Characters

Sheila King sheila@thinkspot.net
Sat, 6 Apr 2002 21:23:08 -0800


On Sat, 06 Apr 2002 22:17:59 -0700, Paul Sidorsky wrote:
> Sheila King wrote:
>
> > In any case, I would still like to know the best way to check to
> > determine whether a character is among the list \000-\037, \0177
> > which are the control characters I've been told to not allow.
>
>
> List comprehensions to the rescue:
>
> > > > ctrlchars = [chr(i) for i in range(040)] + ['0177']
> > > > ctrlchars
> ['\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
> '\x08', '\t', '\n', '\x0b', '\x0c', '\r', '\x0e', '\x0f', '\x10',
> '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18',
> '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', '0177']
>
>
> Then just use the in operator to check for membership as you've
> been doing.
>

Ah, thanks Paul. That is something like what I was looking for, but I 
couldn't quite put my finger on it. :)

-- 
Sheila King
http://www.thinkspot.net/sheila/