欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解決Python中報(bào)錯(cuò)TypeError: must be str, not bytes問(wèn)題

 更新時(shí)間:2020年04月07日 11:34:42   作者:killvoon  
這篇文章主要介紹了解決Python中報(bào)錯(cuò)TypeError: must be str, not bytes問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

如下所示:

#!/usr/bin/python
import pickle 
shoplist=['apple','mango','carrot']
f = open('c:\poem.txt','w')
pickle.dump(shoplist,f)
f.close()
del shoplist
f = open('c:\poem.txt','r')
storedlist = pickle.load(f)
print(storedlist)

執(zhí)行上述程序時(shí)候報(bào)錯(cuò):

TypeError: must be str, not bytes

解決方法:

在使用open打開(kāi)文件的時(shí)候,加個(gè)b

f = open('c:\poem.txt','wb‘)
f = open('c:\poem.txt','rb')

補(bǔ)充知識(shí):TypeError: LoadLibrary() argument 1 must be str, not None

在最新版本的Anaconda3中,新加入了一個(gè)condabin目錄,而新版的anaconda中創(chuàng)建虛擬環(huán)境時(shí)需要依賴(lài)該目錄中的文件,所以會(huì)報(bào)錯(cuò)如下:

解決辦法:

將該目錄加入系統(tǒng)環(huán)境變量中,然后進(jìn)入該目錄打開(kāi)cmd窗口

執(zhí)行 conda create -n DjangoPath python=3.5.2

以上這篇解決Python中報(bào)錯(cuò)TypeError: must be str, not bytes問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論