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
- 從json str 轉成json
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 dump 輸出文本
json.dumps(arr, ensure_ascii=False).encode('utf8')
3. 文件讀寫
4. 多進程
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
