python学习引用文章

上一篇 / 下一篇  2010-01-22 17:13:34 / 个人分类:python

python读取其它格式文件的模块

python读取excel文件数据的方法。一种方法是先把xls文件转换为csv格式文件,然后用csv模块(自带)解释,一种是用xlrd模块(需下载安装)来直接读取文件信息。该模块的网址为:
http://www.lexicon.net/sjmachin/xlrd.htm
例子为:
Quick start:

import xlrd
book = xlrd.open_workbook("myfile.xls")
print "The number of worksheets is", book.nsheets
print "Worksheet name(s):", book.sheet_names()
sh = book.sheet_by_index(0)
print sh.name, sh.nrows, sh.ncols
print "Cell D30 is", sh.cell_value(rowx=29, colx=3)
for rx in range(sh.nrows):
print sh.row(rx)
# Refer to docs for more details.
# Feedback on API is welcomed.
压缩包中的DOC目录带有使用文档及例程。

python解释CSV格式的文件,标准python自有csv模块,在Python Library Reference的第9节有介绍,或者从以下网址可得到一些例子:
http://www.object-craft.com.au/projects/csv/

python读取PDF文件的模块pyPdf:
http://pybrary.net/pyPdf/
带软件包及介绍,例子。


TAG:

 

评分:0

我来说两句

Open Toolbar