16boke - 一路博客

Python 2.x与3​​.x版本区别

1.python2.x  print "Hello"
   python 3.x  print("Hello")

2.老版本 except Exception,e 
   python 2.6之后 except Exception as e

3. python3.3,urllib.request代替urllib2

4.urllib.urlencode ----->  urllib.parse.urlencode

5.TypeError:POST data should be bytes or an iterable of bytes.It cannot be of type str.
   urllib.parse.urlencode(data)--->urllib.parse.urlencode(data).encode(encoding='UTF-8')

6.if isinstance(api,unicode) ---> if isinstance(api,str)
    python3中,unicode函数已改成str函数

7.TypeError:Type str doesn't support the buffer API
    python2.x urllib.quote(text) ---->python 3.x  urllib.parse.quote(text)

8.Python 2.x中的"httplib"模块在Python 3.x中变成了"http.client"

Python