python將字符串list寫入excel和txt的實例
docs = [‘icassp improved human face identification using frequency domain representation facial asymmetry', ‘pattern recognition unsupervised methods classification hyperspectral images low spatial resolution', ‘iscas post layout watermarking method ip protection', ‘computers mathematics applications tauberian theorems product method borel cesàro summability', ‘ieee t. geoscience remote sensing mirs all-weather 1dvar satellite data assimilation retrieval system']
將docs寫入excel
docs = [doc.encode('latin-1', 'ignore') for doc in docs]
# convert list to array
docs_array = np.array(docs)
print(type(docs_array))
# saving...
np.savetxt('/Users/Desktop/portrait/jour_paper_docs.csv', docs_array, fmt='%s', delimiter=',')
print('Finish saving csv file')
結(jié)果

將docs寫入txt
def save(filename, docs):
fh = open(filename, 'w', encoding='utf-8')
for doc in docs:
fh.write(doc)
fh.write('\n')
fh.close()
save('/Users/Desktop/portrait/jour_paper_docs.txt', docs)
結(jié)果

以上這篇python將字符串list寫入excel和txt的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python學(xué)習(xí)-List移除某個值remove和統(tǒng)計值次數(shù)count
這篇文章主要介紹了?python學(xué)習(xí)-List移除某個值remove和統(tǒng)計值次數(shù)count,文章基于python的相關(guān)內(nèi)容展開詳細(xì)介紹,需要的小伙伴可以參考一下2022-04-04
Python requests發(fā)送post請求的一些疑點
在Python爬蟲中,使用requests發(fā)送請求,訪問指定網(wǎng)站,是常見的做法,這篇文章主要介紹了Python requests發(fā)送post請求的一些疑點,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05
Biblibili視頻投稿接口分析并以Python實現(xiàn)自動投稿功能
這篇文章主要介紹了Biblibili視頻投稿接口分析并以Python實現(xiàn)自動投稿功能,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-02-02
Python函數(shù)式編程之返回函數(shù)實例詳解
函數(shù)式編程的一個特點就是,允許把函數(shù)本身作為參數(shù)傳入另一個函數(shù),還允許返回一個函數(shù),下面這篇文章主要給大家介紹了關(guān)于Python函數(shù)式編程之返回函數(shù)的相關(guān)資料,需要的朋友可以參考下2022-09-09
python利用tkinter實現(xiàn)圖片格式轉(zhuǎn)換的示例
這篇文章主要介紹了python利用tkinter實現(xiàn)圖片格式轉(zhuǎn)換,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2020-09-09
詳解Python設(shè)計模式編程中觀察者模式與策略模式的運用
這篇文章主要介紹了Python設(shè)計模式編程中觀察者模式與策略模式的運用,觀察者模式和策略模式都可以歸類為結(jié)構(gòu)型的設(shè)計模式,需要的朋友可以參考下2016-03-03
解決python中os.system調(diào)用exe文件的問題
這篇文章主要介紹了解決python中os.system調(diào)用exe文件的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-05-05

