Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%load answers #23

Open
1 of 4 tasks
nicole-brewer opened this issue Jul 6, 2023 · 3 comments
Open
1 of 4 tasks

%load answers #23

nicole-brewer opened this issue Jul 6, 2023 · 3 comments

Comments

@nicole-brewer
Copy link
Collaborator

nicole-brewer commented Jul 6, 2023

  • Create a script to import answers from key/path/to/file.py

For each notebook:

  • Use nb_export to create py files in dashboard and key/dashboard

Before the tutorial:

  • Remove answers
  • Remove the second call to export that creates the key (i.e nb_export('03_dashboarding.ipynb', '.dashboard_key'))
@nicole-brewer nicole-brewer added this to the complete tutorial milestone Jul 6, 2023
@nicole-brewer
Copy link
Collaborator Author

Okay, instead of making this an issue for every notebook, I'm going to just do something more centralized here. I need to make a script that does a lot of this for me. One goal is to pull in answers to a cell when the user gets stuck. I can see two ways to do this...

  1. Keep two copies of every notebook. One that is hidden and one that isn't. Create cell magic that pulls in the answer from the answer notebook.
  2. Don't have two copies of every notebook. Instead, have two copies of every python file, one of which is an answer key. Use cell magic to pull in the answer from the answer key. Load was giving me trouble because I can't put a comment to the right of it. But if I made my own cell magic, I could.

The part I haven't figured out here is how to deal with editing notebooks.

@nicole-brewer
Copy link
Collaborator Author

Okay so I'm going with option two. I wrote an ipython magic that pulls in code chunks from the exported python file with filepath and cell number parameters. I decided to have the answers (for any part of the tutorial, doesn't have to just be dashboard) go in a key directory. I was going to have it be a hidden folder, but that's not agreeable with the way python imports work. I was thinking about putting the key folder inside the dashboard folder, but that's a bad idea because I don't want bad things to happen if we delete the dashboard folder altogether for some reason

@nicole-brewer
Copy link
Collaborator Author

So perhaps I've established somewhere that the ipython magic that pulls chunks from the exported python file can only do so on exported cells, which is an oversight on my part. What about cells that aren't exported? I was thinking I'd have to scrap the old magic and write a new one that writes all the answers to files, but actually, the old way of doing it is still needed. If a user has trouble with an old notebook, they can import the module from the key directory. So it's not like I wasted work there. But I also need a solution for pulling in answers from cells that weren't exported. So I need to write another magic function that exports answers to a different directory in key. I can write this function so that it leaves in the comments to the right hand side. But when to do this. Could make it an option to leave in the answer until a flag is used. Only then does the code get stripped away leaving the comments. A commented out command with %load or %answer needs to be added before the first line. Probably %answer to keep it consistent. This means I need to add an option to answer that doesn't take a cell number, just a file. The command for exporting the answer could be %%export --hold could prevent the answer being replaced with the comments. This will be a little ugly, because the imported answer needs to have the commented out code on it still in case the code gets exported but then needs to be imported to get changed again. But that's a small thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant