Export/import a dataset to /from a sting

Is it possible to export/import a dataset to/from a string (instead a .csv file)?

I want to save the complete dataset as string in a database field.

The dataset type is serializable, so that would be a possibility: wrap a ByteArrayOutputStream in an ObjectOutputStream, use writeObject() to fill the byte array with the serialized dataset, then save the bytes to a suitable database column.
An alternative is to use java.beans.XMLEncoder … I’ve played with this, but not enough to recommending it yet :slight_smile:

The StringIO module should be good for this.

Easy enough to encode the dataset into a csv string. The issue may be when you pull it back out and need the original data types.

The attached window strives to overcome that.

CSV Strings_2017-06-27_1053.proj (44.7 KB)

Hopefully, this will give you some ideas. :wink:


[quote=“pturmel”]The dataset type is serializable, so that would be a possibility: wrap a ByteArrayOutputStream in an ObjectOutputStream, use writeObject() to fill the byte array with the serialized dataset, then save the bytes to a suitable database column.
[/quote]

That worked perfectly!

[quote=“JordanCClark”]The StringIO module should be good for this.

Easy enough to encode the dataset into a csv string. The issue may be when you pull it back out and need the original data types.

Hopefully, this will give you some ideas. :wink:[/quote]

I’ll also try this!

Thanks