Open aarchiba opened 1 year ago
This is related to numbas/Numbas#558. It would also be nice to be able to place the values of question variables in the filesystem.
This is related to numbas/Numbas#558. It would also be nice to be able to place the values of question variables in the filesystem.
I think simply importing question variables and their values into the Python interpreter as variables would cover nearly all randomization needs with greater convenience. As I understand it there is some kind of syntax that allows one to do this manually with the "variables to include in code" box.
We are writing questions on data analysis and plotting. The skills we want students to practice are loading data from files and plotting realistic data. It would be really helpful if there were some way student code could have access to files we attach to questions; in an ideal world, if students wrote
open("file.txt")
it would findfile.txt
among the question resources. Failing that, referring to files by the URLs would be really helpful.Currently, we have to paste the contents of such files into triple-quoted strings, then create StringIO objects from them. Happily,
np.loadtxt
, like many other data-reading functions, will read from a file-like object as well as a filename, so we can present a variablefilename
containing a StringIO as if it were a filename. Unfortunately we need to paste this into every question part that wants to use the data.It looks like pyodide can provide access to a file system: https://pyodide.org/en/latest/usage/file-system.html This could be pre-loaded from JavaScript with files from the question.