今天在用yaml處理數據時,由於yaml.load可接收一個byte字符串,unicode字符串,打開的二進制文件或文本文件對象,但字節字符串和文件必須是utf-8,utf-16-be或utf-16-le編碼的。因此讀取數據的時候用了
data_file = open("F:\\MyPro\\data.yaml", "r", encoding='utf-8')
運行的時候報錯:TypeError: 'encoding' is an invalid keyword argument for this function
網上查找一番后,改成如下這樣就可以搞定
import io
data_file = io.open("F:\\MyPro\\data.yaml", "r", encoding='utf-8')