col_values problem

612 views
Skip to first unread message

The One Electronic

unread,
Jun 30, 2008, 9:54:33 AM6/30/08
to python-excel
Hi to everybody,

I am using the col_values() method as specified in the official xlrd
documentation.
However this raises an error as follows

Traceback (most recent call last):
File "C:/Python25/PS PRICE LIST/TestXLS.py", line 6, in <module>
PakLabel = sh.col_values(2)
AttributeError: 'Sheet' object has no attribute 'col_values'

My code excerpt is the following:

import xlrd
book = xlrd.open_workbook("C:\Python25\PS PRICE LIST\RecPS.xls")
sh = book.sheet_by_index(0)
PakLabel = sh.col_values(2)
PakValue = sh.col_values(3)

I don't understand this error as everything work fine if I use
row_values() in the same fashion as above.
By the way, I'm running the code on windows xp and python 2.5 and
microsoft excel 2003

Thank you for your help,

Gab

John Machin

unread,
Jun 30, 2008, 4:24:22 PM6/30/08
to python...@googlegroups.com
The One Electronic wrote:
> Hi to everybody,
>
> I am using the col_values() method as specified in the official xlrd
> documentation.

What are you calling "the official xlrd documentation"? What does your
C:\Python25\Lib\site-packages\xlrd\doc\xlrd.html say about Sheet.col_values?

> However this raises an error as follows
>
> Traceback (most recent call last):
> File "C:/Python25/PS PRICE LIST/TestXLS.py", line 6, in <module>
> PakLabel = sh.col_values(2)
> AttributeError: 'Sheet' object has no attribute 'col_values'

Always show the full traceback; what you might assume is irrelevant is
not always so (see below).

>
> My code excerpt is the following:
>
> import xlrd
> book = xlrd.open_workbook("C:\Python25\PS PRICE LIST\RecPS.xls")
> sh = book.sheet_by_index(0)
> PakLabel = sh.col_values(2)
> PakValue = sh.col_values(3)

Not a problem this time, but always when you show the minimal code that
is supposed to demonstrate the problem, give the traceback and other
output from that code, not from some other code.

>
> I don't understand this error as everything work fine if I use
> row_values() in the same fashion as above.
> By the way, I'm running the code on windows xp and python 2.5 and
> microsoft excel 2003

Much more important: what version of xlrd are you running? Consider the
following:

=== latest public release ===
>>> import xlrd
>>> xlrd.__VERSION__
'0.6.1'
>>> bk = xlrd.open_workbook('palette_trial.xls')
>>> sh = bk.sheet_by_index(0)
>>> sh.col_values(1)[:6]
[u'Colour name', u'BLACK', u'WHITE', u'RED', u'GREEN [bright]', u'BLUE']
>>>

=== from HISTORY.html ===
Version 0.6.0a1, 2006-09-08

* Sheet objects have two new convenience methods: col_values(colx,
start_rowx=0, end_rowx=None) and the corresponding col_types. Suggested
by Dennis O'Brien.

=== previous public release ===
>>> import xlrd
>>> xlrd.__VERSION__
'0.5.2'
>>> bk = xlrd.open_workbook('palette_trial.xls')
>>> sh = bk.sheet_by_index(0)
>>> sh.col_values(1)[:6]


Traceback (most recent call last):

File "<stdin>", line 1, in ?
AttributeError: Sheet instance has no attribute 'col_values'
>>>

My guess is that you followed some ancient link you found on the net.
Get the latest public release from http://pypi.python.org/pypi/xlrd or
http://www.lexicon.net/sjmachin/xlrd.htm ...

HTH,
John

The One Electronic

unread,
Jun 30, 2008, 4:49:42 PM6/30/08
to python-excel
Hi John,

I found out that my problem is of a trivial nature.
After googling for it I got the package from here (http://
pypi.python.org/pypi/xlrd/0.5.2) which showed up on top of my google
search.
It took me a while to find out mine's not the latest version, as I
assumed having already got the latest from that page...
Eventually I found one of your answers to somebody pointing out that
there are links pointing to older releases and downloaded the latest
from here (http://www.lexicon.net/sjmachin/xlrd.htm)
Anyway, I'm using this documentation (http://www.lexicon.net/sjmachin/
xlrd.html)
Now the code works just fine

Thank you so much!

Gab
Reply all
Reply to author
Forward
0 new messages