3 ms·
sys.version_info gives you a tuple, which is way more convenient for comparisons than sys.hexversion: if sys.version_info >= (3,): ... # Python 3.
by jwilk 10y 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
- tyingq 10y agoThat is why I used sys.hexversion. Since there are 3 paths, has real bytes, fake str bytes, and no bytes.
- jwilk 10y agobytes exists since Python 2.6. Do you really need to support anything older?
- tyingq 10y agoMaybe 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.