I like using the is None test for empty variables, it’s very flexible, easy and useful. It seems to have stopped working now:
>"" is None
False
>[] is None
False
>{} is None
False
What’s going on?
I’m using Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5], on Debian/Sid i686 GNU/Linux.
Edit: Awesome tip from Sven Marnach of using bool(“”). brb, off to edit some code…
The test
x is Nonetests ifxreally is theNoneobject (that is, if the namexreferences the objectNone). What you are looking for is truth value testing:ifimplicitly converts the condition tobool. You can also explicitly do this: