1. 程式人生 > >TypeError: 'encoding' is an invalid keyword argument for this function

TypeError: 'encoding' is an invalid keyword argument for this function

python 2.7版本

data_file = open("data.txt", "r", encoding='utf-8')

執行的時候報錯:

TypeError: 'encoding' is an invalid keyword argument for this function

解決:

import io

data_file = io.open("data.txt", "r", encoding='utf-8')

參考
python 2.7版本解決TypeError: ‘encoding’ is an invalid keyword argument for this function