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')
结果
将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)
结果
以上这篇python将字符串list写入excel和txt的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
版权声明:
本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。
- 上一篇: python:按行读入,排序然后输出的方法
- 下一篇: python 字符串追加实例