From: Francesc A. <fa...@op...> - 2004-01-20 19:25:53
|
Hi David, You have discovered a bug in the de-serializing process of attribute objects. This is fixed in CVS now and the fix will be included in the soon-to-be-released pytables 0.8. Meanwhile, you can apply a cPickle.loads on the retrieved value. The next code would be useful to mantain forward compatibility in your code with the new pytables version: try: attrval = cPickle.loads(table.attrs.dayIndex) except: retval = table.attrs.dayIndex Regarding the other question, there are several approaches that can easy the access the data, but the one you have adopted is perfectly good. One possible improvement could be to use the datetime module to automatically convert from a date structure into the timestamp (i.e. the number resulting from a time.time() call), and then do the selections in the normal way. That way you don't have to keep the helper dictionary as an attribute. But, of course, a lookup with the dictionary can be faster. It's up to you. Cheers, A Dimarts 20 Gener 2004 18:42, David Sumner va escriure: > Hello, > I am prototyping an application with pytables acting as the storage > layer. I am wanting to add a simple index of the data being collected in > a table. Data collection for this table will occur over weeks and > months. I was wanting to store a timestamp for each day of recorded data > in a dictionary attached to this table with the day timestamp as the key > and the index of the first row being added to the table for this day as > the value. What I was hoping to accomplish was an ability to lookup a > timestamp in the dictionary, returning the row index and then utitlize > that for selection of records or removal of records for particular days. > > What I have done is added a an attribute like so: > table.attrs.dayIndex = {} > > When I first create the hdf5 file and create the groups and tables and > add data, the dayIndex attribute functions as a dictionary should. When > I flush and save this data to the hdf5 file, close and reopen the file, > the attribute becomes a string and no longer functions as a dictionary. > My question is, how may I accomplish this and after a reopening of the > hdf5 file, still utilize python dictionaries stored as attributes? > > Are there other methods that I may use that would be as or more > efficient. Like storing another table as a leaf of the table that stores > the items I want to index. > > Thanks, > David Sumner -- Francesc Alted |