// Numbas version: finer_feedback_settings {"name": "Download text file extension", "extensions": ["download-text-file"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Download text file extension", "tags": [], "metadata": {"description": "
This question demonstrates how to use the \"Download a text file\" extension to create a link to download a file containing text created from question variables.
", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "The \"download a file\" extension makes it easy to provide a text file that the student should download.
\nIt provides a function download_link(filename, content, link_text)
. If you don't give link_text
, the link reads \"Download filename
\".
Here's a text file containing the text \"Hello there\": {download_link(\"hi.txt\",\"Hello there\")}.
\nHere's the same file, but with different link text: {download_link(\"hi.txt\",\"Hello there\",\"Your very own hello file\")}.
\nAnd here's a text file containing a list of numbers, one on each line: {download_link(\"numbers.txt\",join(xs,\"\\n\"))}.
"}, {"type": "information", "useCustomName": true, "customName": "CSV files", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "The extension also provides a function csv(rows,headers)
. rows
should be a list of lists of values. headers
is an optional list of strings to put above the first row.
Here's a table of data:
\n{table_x_y_letter}
\nAs a CSV file, it looks like this:
\n{x_y_letter_csv}\n
{download_link(\"x-y-a.csv\",x_y_letter_csv)}
\nHere's a CSV file with commas and quote characters in the entries, that are automatically escaped for you:
\n{csv(zip(with_commas,with_quotes))}\n
{download_link(\"with-weird-characters.csv\",csv(zip(with_commas,with_quotes)))}
\nOr you can give a dictionary, mapping headers to columns:
\n{csv([\"X\":xs,\"Y\":ys,\"weird data with commas\":with_commas])}\n
{download_link(\"from-dictionary.csv\",csv([\"X\":xs,\"Y\":ys,\"weird data with commas\":with_commas]))}
\nOr you can give a list of dictionaries. There's a column for each distinct key in the dictionaries.
\n{csv(list_of_dicts)}\n
{download_link(\"from-dictionary.csv\",csv(list_of_dicts))}
"}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "type": "question", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}