1. python 2/3 區別
python 2:
print '3 / 2 =', 3 / 2
print '3 // 2 =', 3 // 2
print '3 / 2.0 =', 3 / 2.0
print '3 // 2.0 =', 3 // 2.0
結果:
3 / 2 = 1
3 // 2 = 1
3 / 2.0 = 1.5
3 // 2.0 = 1.0
python3:
print('3 / 2 =', 3 / 2)
print('3 // 2 =', 3 // 2)
print('3 / 2.0 =', 3 / 2.0)
print('3 // 2.0 =', 3 // 2.0)
3 / 2 = 1.5
3 // 2 = 1
3 / 2.0 = 1.5
3 // 2.0 = 1.0
- Unicode
Python 2 有 ASCII str() 類型,unicode() 是單獨的,不是 byte 類型。
現在, 在 Python 3,我們最終有了 Unicode (utf-8) 字符串,以及一個字節類:byte 和 bytearrays。
由於 Python3.X 源碼文件默認使用utf-8編碼,這就使得以下代碼是合法的:
2. json api
for line in f:
data = json.loads(line)
one_data = data.values()
from collections import OrderedDict
for line in f:
data = json.loads(line, object_pairs_hook=OrderedDict)
one_data = data.values()
json.dumps(arr, ensure_ascii=False).encode('utf8')
3. 文件讀寫
4. 多進程