解決python2與python3的一些函數命名的差異

一種較爲簡單的方式是在代碼開頭申明,申明如下:

try:
    raw_input
except NameError:
    raw_input = input

以及如下的方法

try:
    with open('diseases.db.json','r',encoding='utf-8') as indata: #python3
        all_diseases = json.load(indata,strict=False) #python3
except:
    with open('diseases.db.json','r') as indata:
        all_diseases = json.load(indata)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章