[Tutor] 'if a==b or a==c or a==d' alternative (was: pausing a nd layout)

alan.gauld@bt.com alan.gauld@bt.com
Tue Jan 7 13:03:02 2003


> >   if p in 'Qq ':
> >       sys.exit()
> 
> I've just looked thru the new stuff on Python 2.3, and it 
> seems that it will support larger subsplices, so that
> 
> if 'ab' in 'abcdefg':
>     print 'found'
> 
> will actually print 'found'. Which  means that the above 
> example would do a sys.exit() if the user types 'Qq'.

Which is probably better than raising an exception which 
is what it would do now... I guess the solution will be 
to put [0] after the test variable if you really only 
want to test 1 char.

if 'ab'[0] in 'abcdefg':...

But that's not so pretty. However it's countered by the number 
of folks who obviously expect 'ini' to work as it will 
in 2.3 - going by the number of times it crops up as a 'bug' 
on this list.

But yes, I agree it's not entirely backward compatible 
and might well break some old code that relied on 
try/except to catch multi char input... 
- oddly enough I was reading the 2.3 stuff myself at 
the weekend and wondered about that too.

Alan g.