Hi,
I have a problem with using PyTables 1.3 to store strings in a StringCol
column of length 1.
Whenever the string is "", table.append(rows) gives a ValueError exception.
These exceptions only appear for StringCols of length 1; everything is
fine if the length is 2 or higher.
This seems to be a consequence of how numarray pads/strips CharArray
strings.
Does anyone have any suggestions for a work-around?
At the moment, my best idea is to save str+'\x00'.
Code illustrating this is below.
Cheers
Stephen Simmons
---------------------------------------------
from tables import *
hdf = openFile('c:/test.hdf', 'w')
for str_width in [ 1, 2]:
print "\nTesting a table with a column of width %d" % str_width
col_desc = { 'a': StringCol(length=str_width) }
tbl = hdf.createTable(hdf.root, 'table%d'%str_width, col_desc )
for s in [ 'ab', 'c', '', ''+'\x00', 'd'+'\x00', 'ef'+'\x00' ]:
try:
tbl.append( [ [s], ] )
print "Appended %r" % s
except ValueError:
print "Failed to append %r" % s
tbl.flush()
print "This is what is in the table: %r" % [ r['a'] for r in tbl ]
hdf.close()
"""
Output is:
Testing a table with a column of width 2
Appended 'ab'
Appended 'c'
Appended ''
Appended '\x00'
Appended 'd\x00'
Appended 'ef\x00'
This is what is in the table: ['ab', 'c', '', '', 'd', 'ef']
Testing a table with a column of width 1
Appended 'ab'
Appended 'c'
Failed to append ''
Appended '\x00'
Appended 'd\x00'
Appended 'ef\x00'
This is what is in the table: ['a', 'c', '', 'd', 'e']
"""
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users