python将字符串list写入excel和txt的实例

yipeiwu_com6年前Python基础

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的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python编程测试电脑开启最大线程数实例代码

python编程测试电脑开启最大线程数实例代码

本文实例代码主要实现python编程测试电脑开启最大线程数,具体实现代码如下。 #!/usr/bin/env python #coding=gbk import thr...

Python中实现三目运算的方法

C语言中三目运算符 复制代码 代码如下:    expression ?expr1:expr2;  //expression 为真则取表达式expr...

Python2.X/Python3.X中urllib库区别讲解

本文介绍urllib库在不同版本的Python中的变动,并以Python3.X讲解urllib库的相关用法。 urllib库对照速查表 Python2.X...

python常见的格式化输出小结

本文总结了一些简单基本的输出格式化形式,下面话不多说了,来看看详细的介绍吧。 一、打印字符串 >>> print "I'm %s" % ("jihite") I'...

用Python脚本生成Android SALT扰码的方法

复制代码 代码如下:#!/usr/bin/python   # Filename: gen_salt.py   import random&nbs...