天天看點

TypeError: write() argument must be str, not bytes

python用write()寫入檔案時報錯TypeError: write() argument must be str, not byteswith

原因:python3中open()的參數encoding預設值為utf-8,是以讀寫檔案時隻能用Unicode編碼的字元,而不能使用二進制字元

解決方法:以wb或者rb的方式打開檔案就可以進行檔案讀寫了