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

yipeiwu_com5年前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中使用partial改变方法默认参数实例

Python 标准库中 functools库中有很多对方法很有有操作的封装,partial Objects就是其中之一,他是对方法参数默认值的修改。 下面就看下简单的应用测试。 复制代码...

python距离测量的方法

之所以写这个,其实就是希望能对距离有一些概念,当然这个也是很基础的,不过千里之行始于足下嘛,各种路径算法,比如a*什么的都会用到这个 距离测量有三种方式 1、欧式距离,这个是最常用的距离...

关于Python 常用获取元素 Driver 总结

1、在 Windows 设置临时环境变量 cmd命令窗口 输入 path=%path%;E:\soft\python-3.5.2-embed-win32 永久配置,在系统变量下找到pat...

pycharm中显示CSS提示的知识点总结

pycharm中显示CSS提示的知识点总结

我们用pycharm写CSS的时候,是不是苦于没有提示,那么pycharm中如何显示CSS提示呢?下面小编给大家分享一下。 首先点击左上角的file菜单,选择Setting 接着选择E...

Python 基础之字符串string详解及实例

Python字符串(string) 详解 及 代码 Python的字符串可以使用单引号('), 双引号("), 三引号('''); 三引号(''')里面, 可以添加单引号和双引号, 也可...