Is python "str is bytes" equivalent to the sys.version_info test?

Is it right to use

if str is bytes: ...

instead

if sys.version_info < (3,): ...

to distinguish python2 from python3? Especially when version-specific code is required precisely because of the possibility that str is not unicode, it sometimes seems to me that it seems clearer (and avoids often free sys imports), but I have never seen python code that uses this test. Is "str is bytes" true only as a fad of CPython version 2 or is it guaranteed in all python2s?

+4
source share
1 answer

Please use sys.version_info < (3,)to inform readers that you are trying to identify the case of python2.

+3
source

Source: https://habr.com/ru/post/1689516/


All Articles