Aw: Try: Except: evaluates to True every time

Karsten Hilbert Karsten.Hilbert at gmx.net
Sun Nov 5 05:53:07 EST 2017


On Sun, Nov 05, 2017 at 11:28:44AM +1100, Steve D'Aprano wrote:

> > Try in an interactive interpreter:
> > 
> >    python> "a string" is True
> 
> Did you try that yourself?

Yes, eventually, which is why I corrected myself publicly.

However, while it doesn't return True (as I mistakenly
suggested) it does return False, always, which is the very
same reason for OP's problem, namely returning a string,
doing a logic test on that, and assuming that would tell
whether the check succeeded or failed.

Unless I am totally mistaken :-)

Karsten
-- 
GPG key ID E4071346 @ eu.pool.sks-keyservers.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346



More information about the Python-list mailing list