Hi folks,
  Sorry if this has been addressed before, I nosed around a little bit but
didn't see anything related to what I'm currently experiencing. I've been
trying to find a way to store some variable-length data in my
IsDescription-derived table row, and I tried to do it by creating a
StringCol with a maximum width, and then byte-packing my data with
struct.pack() and writing the bytestring to the table row. However, when I
read back the written string from the file, the bytestring has been
truncated. I've attached an example where I try to write out a length-240
string and get back a length 237 string.

This is with PyTables 2.1.2 and numpy 1.3. Thanks in advance.

--cb
import cPickle as pickle
import struct

import tables

class MyRow(tables.IsDescription):
    run    = tables.Int32Col()
    event  = tables.Int32Col()
    nstr   = tables.Int32Col()
    bstr   = tables.StringCol(4*6*100)


fp = tables.openFile("strtest.h5", 'w')

nt = fp.createTable(fp.root, "nt", MyRow, "yea")

nt.row['run']   = 10
nt.row['event'] = 1

bstr_vals = []

i = 0
while i < 10:
    bstr_vals.append((float(i)*10,
                     float(i)*10,
                     float(i)*10,
                     i,
                     i,
                     i))
    i+=1

bytestr = ''
for row in bstr_vals:
    bytestr += struct.pack("fffiii", *row)

print "before", len(bytestr), 4*6*100

nt.row['nstr'] = len(bstr_vals)
nt.row['bstr'] = bytestr

nt.row.append()
nt.flush()

fp.close()


fp = tables.openFile("strtest.h5")

nstr    = fp.root.nt[0]['nstr']
bytestr = fp.root.nt[0]['bstr']

print "after", len(bytestr)
print struct.unpack(nstr * "fffiii", bytestr)
------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly 
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus 
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to