2019-03-04
閱讀量:
600
Python如何將數(shù)據(jù)寫入文件?
Python如何將數(shù)據(jù)寫入文件?
答:寫入文件首先需要打開文件,然后再通過打開的文件對象進行寫操作
outfile = open("D:\\test02.txt","w") #在D盤建一個名為test02的文件,若存在則不會創(chuàng)建
outfile.writelines(["Hello"," ","World"]) #寫入數(shù)據(jù)
outfile.close()
infile = open("D:\\test02.txt","r").read() #讀取數(shù)據(jù)
print(infile)
# 輸出結(jié)果
Hello World
Python文件寫入方法如下:







評論(0)


暫無數(shù)據(jù)
推薦帖子
0條評論
0條評論
0條評論
0條評論