os
获得当前工作目录
os.getcwd()
切换目录
os.chdir('../123')
pickle
保存数据
pickle.dump(要保存的数据,目标文件)
import pickle
try:
with open('test1.txt','wb') as test1, open('test2.txt','wb') as test2:
pickle.dump('new world',test1)
pickle.dump('old world',test2)
except IOError as ierr:
print("File Error:"+str(ierr))
except pickle.PickleError as perr:
print("Picking Error:"+str(perr))
恢复数据
pickle.load(目标文件)
try:
with open('test1.txt','rb') as test1, open('test2.txt','rb') as test2:
n_test1 = pickle.load(test1)
except IOError as ierr:
print("File Error:"+str(ierr))
except pickle.PickleError as perr:
print("Picking Error:"+str(perr))
>>> n_test1
'new world'