- subprocess返回的output中有
\n
- bytes到str的转换
参考: https://blog.youkuaiyun.com/weixin_40283816/article/details/83591582
b = b"example"
s = "example"
sb = bytes(s, encoding = "utf8")
或者:sb = str.encode(s)
bs = str(b, encoding = "utf8")
或者:bs = bytes.decode(b)
- urllib和urllib2的转换
参考: https://blog.youkuaiyun.com/python36/article/details/84568183
Py2.x:
Urllib库
Urllin2库
Py3.x:
Urllib库
变化:
在Pytho2.x中使用import urllib2——-对应的,在Python3.x中会使用import urllib.request,urllib.error。
在Pytho2.x中使用import urllib——-对应的,在Python3.x中会使用import urllib.request,urllib.error,urllib.parse。
在Pytho2.x中使用import urlparse——-对应的,在Python3.x中会使用import urllib.parse。
在Pytho2.x中使用import urlopen——-对应的,在Python3.x中会使用import urllib.request.urlopen。
在Pytho2.x中使用import urlencode——-对应的,在Python3.x中会使用import urllib.parse.urlencode。
在Pytho2.x中使用import urllib.quote——-对应的,在Python3.x中会使用import urllib.request.quote。
在Pytho2.x中使用cookielib.CookieJar——-对应的,在Python3.x中会使用http.CookieJar。
在Pytho2.x中使用urllib2.Request——-对应的,在Python3.x中会使用urllib.request.Request.