Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the pythonic way to reconstruct a serialized object
    primarykey
    data
    text
    <p>the more I work with python, the more I want to do it the pythonic way, i.e. try to avoid isinstance queries etc. I am developing a framework for scientific parameter exploration for numeric simulation. </p> <p>I work with two hard constraints: First, I need to be able to repeat a specific simulation I stored to disk exactly the way it was run for the first time. Secondly, data should be nice and readable in hdf5/pytables format.</p> <p>Both concepts are a bit opposing. As soon as I store stuff as pytables data, some information is lost. For instance, after reloading a python int becomes a numpy.int64. This can be problematic if you want to rerun numerical simulations, because there are cases where a multiplication of a variable with an int works fine but breaks when used with numpy.int64. This is the case, for example, if you use the spiking neural network simulator BRIAN.</p> <p>So a straightforward answer would be to simply pickle everything and get it back as it was before. Yet, this doesn't work well with the idea of readable hdf5 array or table data. </p> <p>So what I have in mind is to store the original data format as an hdf5 attribute to the corresponding table or array and use this information to reconstruct the original data. First, is that a good idea in general, and second, what is the most pythonic way to do that?</p> <p>For instance, what about this:</p> <pre><code>original_class_name = data.__class__.__name__ # do the storage of data and the original_class_name {...} # load the hdf5data and reconstruct it reconstructed_data = eval(original_class_name+'(hdf5data)') </code></pre> <p>To me this seems too hacky.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload