编写python23兼容代码

1、six模块
2、2to3等工具转换代码
3、__future__

 


https://six.readthedocs.io/#

 


import six six.PY2 #返回一个表示当前运行环境是否为python2的boolean值 six.PY3 #返回一个表示当前运行环境是否为python3的boolean值 six.integer_types # 在python2中,存在
intlong 两种整数类型;在python3中,仅存在一种类型int six.string_types # 在python2中,使用的为basestring;在python3中,使用的为str six.text_type # 在python2中,使用的文本字符的类型为unicode;在python3中使用的文本字符的类型为str six.binary_type # 在python2中,使用的字节序列的类型为str;在python3中使用的字节序列的类型为bytes

 

posted @ 2020-06-14 09:05  慕沁  阅读(247)  评论(0)    收藏  举报