How can i use Spread Sheet as Data Store

John Machin sjmachin at lexicon.net
Mon May 18 19:29:38 EDT 2009


On May 19, 5:12 am, Terry Reedy <tjre... at udel.edu> wrote:
> Kalyan Chakravarthy wrote:
> > Hi All,
> >              I have data in Spread Sheet ( First Name and Last Name),
> > how can i see  this data  in Python code ( how can i use Spread Sheet as
> > Data Store ) .
>
> I you have a choice, a plain text file is MUCH easier.

for line in open('guff.txt'):
    first, last = line.rstrip('\n').split('\t')

> Or, you can output a plain text data.csv (comma-separated variable) file
> from the spreadsheet and read that with the csv module.

import csv
for row in csv.reader(open('guff.csv', 'rb')):
    first, last = row

Or, if you have an Excel XLS file, use xlrd:

import xlrd
book = xlrd.open_workbook('guff.xls')
sheet = book.sheet_by_index(0)
for rowx in xrange(sheet.nrows):
    first, last = sheet.row_values(rowx)

So far I don't see "MUCH" easier ... than what? Perhaps much easier
than using odfpy, which states right up front """Odfpy aims to be a
complete API for OpenDocument in Python. Unlike other more convenient
APIs, this one is essentially an abstraction layer just above the XML
format.""" Perhaps much easier than using COM?



More information about the Python-list mailing list