存文件的三种方式:
txt文件
with open('目录.txt','a',encoding
='utf-8') as f
:
f
.write
(alist
+'\n')
csv文件
with open('qdzw.csv','w',encoding
='utf-8') as f
:
writer
= csv
.writer
(f
,delimiter
=',')
writer
.writerow
(['title','author','cont'])
with open('qdzw.csv','a',encoding
='utf-8') as f
:
writer
= csv
.writer
(f
, delimiter
=',')
writer
.writerow
([title
,author
,cont
])
json文件
lst
= []
dic
= {}
dic
['title'] = title
dic
['author'] = author
dic
['cont'] = cont
lst
.append
(dic
)
with open('qdzw.json', 'a', encoding
='utf-8') as f
:
f
.write
(json
.dumps
(lst
, indent
=4, ensure_ascii
=False))
转载请注明原文地址:https://ipadbbs.8miu.com/read-1868.html