Hacker News new | ask | show | jobs
by jwilk 3347 days ago
sys.version_info gives you a tuple, which is way more convenient for comparisons than sys.hexversion:

    if sys.version_info >= (3,):
        ...  # Python 3.X code
Or you could check whether str is bytes:

    if str is bytes:
        ...  # Python 2.X code
1 comments

That is why I used sys.hexversion. Since there are 3 paths, has real bytes, fake str bytes, and no bytes.
bytes exists since Python 2.6. Do you really need to support anything older?
Maybe not, but the incremental work was less than making a single codebase work for both 2 and 3. It's code that runs on openwrt, so forcing my ideas on the users is painful for them...they would have to build a whole new image.