Avoid Version Numbers
Posted Feb 15, 2011 1:48 UTC (Tue) by
ldo (subscriber, #40946)
Parent article:
Moving to Python 3
I hate version numbers. Dont check for version numbers; instead, check for something as close as possible to the actual functionality you need.
Python even helps you, by providing ways to query it for things. E.g. to check for the bytes function, you dont have to go through the rigmarole of watching for a NameError exception; just write
hasattr(__builtins__, "bytes")
What could be simpler? And similarly the PYTHON3 version check could be replaced with something like
not hasattr(__builtins__, "unichr")
(Negated so its True for Python 3.x and False for earlier versions.)
(
Log in to post comments)