[Python-Dev] other "magic strings" issues

Alex Martelli aleaxit at yahoo.com
Fri Nov 7 16:04:15 EST 2003

On Friday 07 November 2003 20:04, Raymond Hettinger wrote:
> > Ah gotcha.  I'd definitely want to retain ascii_letters, probably
> > ascii_lowercase and ascii_uppercase, digits, hexdigits, octdigits,
> > punctuation, printable, and whitespace
> Other than possibly upper and lower, the rest should be skipped and left
> for tests like isdigit().  The tests are faster than the usual linear
> search style of:   if char in str.letters.

I guess the tests should be faster, yes, but I would still want _iterables_
for ascii_*  and digits.

One issue with allowing "if char in string.letters:" is that these days this
will not raise if the alleged 'char' is more than one character -- it will 
give True for (e.g.) 'ab', False for (e.g.) 'foobar', since it tests 

So, maybe, str.letters and friends should be iterables which also implement 
a __contains__ method that raises some error with helpful information about 
using .iswhatever() instead -- that's assuming we want people NOT to test 
with "if char in str.letters:".  If we DO want people to test that way, 
then I think str.letters should _still_ have __contains__, but specifically 
one to optimize speed in this case (if supported it should be just as fast 
as the .is... method -- which as Skip reminds us may in turn need 


More information about the Python-Dev mailing list