I'm afraid the above isn't very coherent an explanation of what data you
expect to be in these cells and why. Where does this sheet come from?
What leads you to have your expectations about the cell contents?
> function. Obviously 5 out of 15k isn't too bad, but nevertheless.
That's an alarming statement. Intermittent, unexplained failures would
be far more worrying that every single cell behaving in a particular
fashion. I suspect these cells are of a different type, but you've given
no indication of where the workbook originates from.
Can you provide a small workbook and *actual code* (not snippets) that
demonstrates the problem?
> I'm using this code to test. (same problem happens if you do
> sheet.cell(cell,0).value though)
>
> import xlrd
> wb = open_workbook('test.xls')
> sheet = wb.sheet_by_index(0)
>
> cells = [0,1]
> for cell in cells:
> print str(sheet.cell_type(cell,0)) + str(sheet.cell_value(cell,0))
This doesn't match with your quoted output above, it'd also raise an
exception if run. It's also a rather odd way of doing things...
What I would do is install xlutils, and then do:
from xlrd import open_workbook
from xlutils.display import cell_display
wb = open_workbook('test.xls')
sheet = wb.sheet_by_index(0)
for rowx in range(1):
print cell_display(sheet.cell(rowx,0)
...and see if you find the output enlightening.
cheers,
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
It's not clear what you're trying to say here. Perhaps you could attach
said blank workbook so we can have a look?
> What leads me to have my expectations of the content of the cells is
> simply that is what I see if I open the workbook,
In what? Excel? With it's well known habbit of formatting data when you
open it rather than actually showing you what's in a cell?
> 287100.... but when i use the library to read the number it says
> 2870:0.0 (sorry, i had typo'd an extra two in my original post) -- no
> idea where the colon is coming from.
Again, copy'n'paste, don't type from memory. I still have no idea what
"2870:0.0" is or where you're getting it from...
Chris
It's interesting that the first line doesn't have a problem:
287010 -> OK
281210 -> bad
236210 -> bad
> 22870:0.0
> 1287100
> 1thomas
> 22870:0.0
> 228120:.0
> 22600:0.0
> 223620:.0
> 1281210
> 1260100
> 1236210
Please save the following code as (say) Jody_colon.py and run it from
the command prompt specifying the name of your file (wrapped in quotes
if you persist in having spaces in the name).
=== start of Jody_colon.py ===
import sys
print 'sys.version:', sys.version
print 'sys.stdout.encoding:', sys.stdout.encoding
import locale
print 'locale.getdefaultlocale:', locale.getdefaultlocale()
import platform
print 'platform.platform:', platform.platform()
# Test that str and repr work OK with the suspect numbers
for x in [287010.0, 287100.0, 281210.0, 260100.0, 236210.0]:
print x, str(x), repr(x)
print
import xlrd
print 'xlrd.__VERSION__', xlrd.__VERSION__
wb = xlrd.open_workbook(sys.argv[1])
sheet = wb.sheet_by_index(0)
for rowx in xrange(sheet.nrows):
value = sheet.cell_value(rowx, 0)
print ("row# %d, ty %d, str<%s>, repr<%r>"
% (rowx + 1, sheet.cell_type(rowx,0), value, value)
)
=== end of Jody_colon.py ===
When I run this, I get the following on my computer:
=== start of output ===
C:\wherever\Jody_colon>\python27\python Jody_colon.py Jody_colon.xls
sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit
(Intel)]
sys.stdout.encoding: cp850
locale.getdefaultlocale: ('en_AU', 'cp1252')
platform.platform: Windows-XP-5.1.2600-SP3
287010.0 287010.0 287010.0
287100.0 287100.0 287100.0
281210.0 281210.0 281210.0
260100.0 260100.0 260100.0
236210.0 236210.0 236210.0
xlrd.__VERSION__ 0.7.1
row# 1, ty 2, str<287010.0>, repr<287010.0>
row# 2, ty 2, str<287100.0>, repr<287100.0>
row# 3, ty 1, str<287100>, repr<u'287100'>
row# 4, ty 1, str<thomas>, repr<u'thomas'>
row# 5, ty 2, str<287100.0>, repr<287100.0>
row# 6, ty 2, str<281210.0>, repr<281210.0>
row# 7, ty 2, str<260100.0>, repr<260100.0>
row# 8, ty 2, str<236210.0>, repr<236210.0>
row# 9, ty 1, str<281210>, repr<u'281210'>
row# 10, ty 1, str<260100>, repr<u'260100'>
row# 11, ty 1, str<236210>, repr<u'236210'>
=== end of output ===
Essentially the same output from Python 2.X for 3 <= X <= 7. In short, I
can't reproduce your problem. Please show the output (copy/paste, don't
edit/retype) that you get on both your home computer and your work computer.
WHAT PROBLEM? Your output below is identical to mine (apart from the
minor locale/encoding differences. I see no colon here.
> On Sep 26, 5:19 am, John Machin<sjmac...@lexicon.net> wrote:
>>
>> When I run this, I get the following on my computer:
>>
>> === start of output ===
>> C:\wherever\Jody_colon>\python27\python Jody_colon.py Jody_colon.xls
>> sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit
>> (Intel)]
HMMMM:
Jody (work): sys.version: 2.7 (r27:82500, Aug 23 2010, 17:18:21) etc
John : sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) etc
I have just now downloaded the Windows x86 msi from www.python.org and
reinstalled it on another computer. It gives the same result as on my
primary computer (above).
Looks whacked: lower revision number, later date.
AFAIK print x will call x.__str__ if it exists otherwise x.__repr__ if
it exists otherwise it will fake it e.g. '<__main__.Bar object at
0x00D54890>'
>>
>> Jody (work): sys.version: 2.7 (r27:82500, Aug 23 2010, 17:18:21) etc
>> John : sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) etc
>>
>> I have just now downloaded the Windows x86 msi fromwww.python.organd
>> reinstalled it on another computer. It gives the same result as on my
>> primary computer (above).
>>
>> Looks whacked: lower revision number, later date.
My correspondents tell me that it appears that you are using an
ActiveState distribution instead of the python.org distribution, and
that this shouldn't make any difference.
--
Georgi Georgiev
DIRECT SERVICES Ltd.
tel: +359-2-9609754
+359-2-9609737
fax: +359-2-9609738
www.directservices.bg