python 读写文件

来源:互联网 发布:费用优化的步骤 编辑:程序博客网 时间:2024/06/17 10:59

1.python 读写excel文件
读取文件使用xlrd 包.
参考资料
python 支持中文,需要在首行中加入

#_*_coding:utf-8_*_import xlrddef read_xls():  xlsname = '/Users/deepmind/Downloads/data.xlsx'  data = xlrd.open_workbook(xlsname)  table = data.sheets()[0]  for i in range(1,table.nrows):      for j in range(table.ncols):          x = table.row(i)[j].value          print x

python 读写word文档

from docx import Documentdocument = Document()document.add_paragraph('This is a paragraph')document.save('doc_test.docx')
0 0