Coming from a C background to Python, I made the assumption that Python's None value was to be used much like a NULL pointer in C. Based on this assumption, I happily coded away using patterns like "if not function()", much like you would say "if !fgets(...)" in C. Only after running into some non-obvious bugs did the wisdom of "always explicitly test for None" become clearer to me.
Issue #4: None, empty and nothing.

Comments
[...] The Python Tourist
[...] The Python Tourist takes a look at Testing for None in Python. It sounds like a simple enough topic, but it’s really an interesting read if you are new to the language. Definitely recommended reading. [...]
Post new comment