How to create a .csv file from a glowscript simulation?

168 views
Skip to first unread message

ad...@prof.ce.gov.br

unread,
Jul 5, 2020, 7:20:01 PM7/5/20
to VPython-users

I'm trying the following code out of the loop: 

file = open ("home / chronos / user / Downloads / data.csv", "w", encoding = "UTF-8") file.write ("t (s), y1 (m), y2 (m), v1 (m / s), v2 (m / s), a1 (m / s ^ 2), a2 (m / s ^ 2 ) \ n ") 
 
and this one inside: 

file.write (str (t) + "," + str (b1.pos.y) + "," + str (b2.pos.y) + "," + str (b1.vy) + "," + str (b2.vy) \ + "," + str (b1.a.y) + "," + str (b2.a.y) + "\ n") 
 file.close ()


Bruce Sherwood

unread,
Jul 5, 2020, 8:19:54 PM7/5/20
to VPython-users
This is a purely Python issue, not a VPython issue. If no one addresses your question here, you might try asking in a Python-user forum, or in stackoverflow.com.

Bruce

Bruce Sherwood

unread,
Jul 5, 2020, 8:24:57 PM7/5/20
to VPython-users
If your program is at glowscript.org, you need to know that you cannot write to your hard drive, due to security issues in browsers. So the Python commands open, write, and close are not available. What you can do is print the material, then in the print region press ctrl-a to select all, ctrl-c to copy, then ctrl-v to paste into a local text editor and save the file.

Bruce

Hal McKinney

unread,
Feb 11, 2023, 2:26:52 PM2/11/23
to VPython-users
I'm just now learning some of this (and LOVE it) and in GlowScript  you can read a file from anywhere via dialog box & you can write to downloads folder (which I have done)... but no direct programmatic access to/from files due to security restrictions of browsers.

See:
https://www.glowscript.org/docs/VPythonDocs/files.html

I'm currently trying to figure out how to get json support without having to parse my own data.

-Hal
Reply all
Reply to author
Forward
0 new messages