Am 29.08.2018 um 03:11 schrieb Allin Cottrell:
On Tue, 28 Aug 2018, Sven Schreiber wrote:
> I thought it would be nice if more object types than series and
> matrix could be re-used in a python foreign block. So I'm attaching a
> first attempt at a python function (gretl_bdlimport) which takes an
> XML text file representing a gretl bundle (as written by gretl's
> bwrite), and copies (some of) its contents to a python dictionary,
> with the same keys as in the original bundle.
Cool! Please keep us updated on this.
Here's the next round. It now covers the following types as convertible
bundle members: scalar, string, matrix, strings, matrices. (Lists and
series are already mostly covered by gretl, and nested bundles or arrays
of bundles are too complicated.) And it now does roundtripping:
- gretl_loadbundle is for conversion of a gretl bundle (in an XML file
as written by bwrite) to a python dictionary
- gretl_exportbundle is to take a python dict and write out an XML file
that can (hopefully) be read by gretl's bread
Arrays (of matrices, strings) are mapped to Python lists (of numpy
ndarrays in the matrix variant, strings).
There's minimal testing code included, so if you just run the file in
python you get a xml file with a gretl bundle as a result. Required
Python modules are: numpy, gzip, io, xml.etree.ElementTree, don't know
how restrictive or demanding that is. Python3 only, as mentioned before.