A Saturday 04 December 2010 06:02:40 Craig the Demolishor escrigué: > 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.
What you are trying to do is not safe because NumPy is truncating strings for all trailing zeros. Look at this: >>> s = struct.pack("ii", 1, 0) >>> s '\x01\x00\x00\x00\x00\x00\x00\x00' >>> len(s) 8 >>> np.array([(1,s)], "i4,S8")['f1'] array(['\x01'], dtype='|S8') >>> len(np.array([(1,s)], "i4,S8")['f1']) 1 As PyTables uses NumPy under the hood, this behaviour is inherited. If you want to use variable length data, your best bet is to use a VLArray object. You can still mix tabular data with variable length data by putting all columns that are variable length in VLArrays. Hope this helps, -- Francesc Alted ------------------------------------------------------------------------------ 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