Any way to export table content from a SNAP program to a file?

The SNAP Manual shows how easily upload data from a csv file to a table. works.
I am now looking for the opposite way to EXPORT data from a table in a SNAP program to a file.
I figured out I could download the file as XML and get the table data out of the XML file, but I am not sure if there is a faster and better way. Not urgent.

1 Like

Sure. You can do pretty much exactly the opposite of what you did to convert a CSV string into a table. You did that in two steps:

  1. SPLIT by lines
  2. MAP (SPLIT by commas)

To convert a table to CSV, you reverse the two steps. The opposite of SPLIT is JOIN, so the two steps are

  1. MAP (JOIN with commas)
  2. JOIN with newline characters

... and then write to a file by right-clicking the watcher and choosing "export."

Do you want actual code, or would you rather work out the details from here yourself?

Thanks a lot for your fast response. I looked into my watcher and didn't find any export.
watcher

export%20tabel

I just figured out that export function appears once there is only 1 element, so I guess I just have to go through the steps and then the export function will appear.

Yeah, right now, it’s text only. It’s definitely on our list of things to make easier. :slight_smile:

The import works fine: image

But I am struggling with joining the table with a "newline characters."
How can I join a carriage return????
I guess its very easy and I am just too tired now.

Ah, very close. You don't want the NL symbol, which is what you use to talk about a newline without actually starting a new line. (Interestingly, it doesn't work in Discourse, which did show an actual newline when I tried to insert that symbol!) What you want is 000A, or 10 decimal, which, to my surprise, Unicode calls "line feed." Since the introduction of the Model 37 Teletype in 1968, that character combines the function of carriage return and linefeed, and I was surprised when looking up ASCII in Wikipedia to learn that the official name wasn't changed to "newline" at the same time leftarrow was changed to underscore. But when Unix came along, the escape sequence to insert that character in a text string was "\n" for newline, and that convention is now universal.

Sorry for the confusion! So here's what you need:

Only one comment more...

As Brian have shown, "unicode (10) as letter" is fine to get a "carriage return".

If you are building these scripts with students and you don't want to use unicode codes, you can use the library "Allow multi-line text input to a block", and then, your "carriage return" will be more visual.

joinReturn1 and joinReturn2

1 Like


Thank you so much for your quick reply. The snippet from Brian did not work, but I can proudly say, I figured it out myself. The items were were missing in the join-operator. Unicode 10 was the information I was missing.

I wish there was a seamless way to upload and download directly in the presentation mode. Is this coming sometime?

P.S. Sorry for my ugly imperative step by step approach with 2 assignments, Brians combine-map version is far more elegant, but I am not that good yet.

Oops! Of course I really meant another COMBINE WITH inside the MAP. :frowning:

We'll probably introduce a way to export and import lists that automatically convert to and from CSV at some point. What we can't do is import from and export to fixed filenames built into a script, because Javascript won't let us.

Hmmm... should we make exporting lists and tables more easily available without the need for advanced hackery?

2 Likes

should we make exporting lists and tables more easily available
Pleeease!!!
I am working on a database for friends and their addresses to teach my students and kids some real stuff. I am thrilled by the OOP techniques possible (e.g. program of screenshot uses inheritance. Far from finished).
BUT - and this is a big BUT - it is so much more fun and so much more useful if you build something you can use your creation in your daily life. SNAP is great, but it lacks a few capabilities to create and build something you can use. Downloading and uploading tables without switching between presentation mode and creation mode to is one of the missing features. I can't use snapp.citilab.eu to build something which runs standalone if I have to switch between modes.
So pleeease add this function.

Other option is to create my custom javascript based file upload. Just not sure if this is possible.
(Example https://fineuploader.com/demos.html )
I just lack experience and don;t have time now since I have to finalize my ERP System in SNAP first.

I hope those aren't those people's real birthdays... That's PII we don't want to host.

Yes! Of course! :slight_smile: @bromagosa has a great PR that does this which was ready at one point, but now could probably use just a tiny bit of work.

1 Like

They are of course not real data. The point is to create a standalone application. I have experienced that kids like the app inventor because they can build applications they can use in day to day life. That sets free motivation to dig into programming.

Well, I think it would be nice to be able to collect real and especially live data, i.e. to have some kind of persistence for lists and tables in our cloud. I would love to use Snap! to track sensor data and notes etc., One way is, of course, to re-save the project and persist data inside the project, but that puts the code at risk. Another idea is to use a REST API with some cloud service such as Google Docs or Dropbox. Or we could implement our own cloud variables...

So, the issue about making it easy to export and import data is atomicity. If it's only text and numbers we can support CSV, and that's what I would prefer. As far as nesting is concerned we can support up to two dimensions, i.e. a table, with CSV. That's what I would suggest. I know some of you will want to exchange anything, including tables of sprites and lists of costumes, but for most cases lists and tables of atomic data will be perfect.

Thoughts?

Agree. CSV is enough.

It'd be nice to have something like the backpack so costumes and sounds can be saved. That's not asking for lists of costumes; it's a different desideratum.

But saving costumes and sounds is already super easy right? Just export them with their context menu, and you even get a "back pack" at the bottom of your browser that you can just drag into any other Snap session...

:smiley: Yeah I guess so. But then you can't get to them on another computer. If we had "export to cloud" that would be better.