python2 升级到 python3

python2/python3 升级对比


0、环境说明

linux 3.2.54

pyhton2.7

升级到

pyhton3.6


1、特性比较

catch语法:catch xxx, xx => catch xxx as xx

print语法:print xxx => print(xxx)

urllib2包:==> urllib.request

commands包: ==> subprocess

base64函数:decodestring => decodebytes

ConfigParser包: ==> configparse

整除: / => //

最大整数:sys.maxint => sys.maxsize

去掉unicode、long关键字,字符编码默认unicode,整数都为long

urllib.request.Request post数据需要转为字节型:bytes(data_str, 'utf-8')

import 包 需要补全路径

 

posted @ 2020-04-24 13:48  heaventouch  阅读(223)  评论(0编辑  收藏  举报