You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@drphilmarshall suggested using %load file.py as a way to move large blocks of dense code into external modules and then optionally display them. Try this out and look for opportunities to improve the flow of a live tutorial with this technique. This method can also be usesd to reveal the solution to an exercise.
The text was updated successfully, but these errors were encountered:
The good thing is that it allows you to use Jupyter magic commands, the bad things are that I have to define this function somewhere, and that it just appears as text, not as a executable (there also exists the possibility of importing the whole notebook using the link above.
The way I would use %load is to create a file helpers.py that defines functions used to make plots, etc, where the code details are distracting to someone seeing the tutorial for the first time:
def plot1():
...
def example2():
...
I don't think this file should have any if __name__ == "__main__" boilerplate and any imports it needs should be imported in the notebook instead.
Next, import helpers at the top of the notebook and call these functions throughout. Somewhere near the top, explain that the code of any helper can be displayed (and modified and re-run) in the notebook using, e.g.
%load -s example2 helpers
When you run this cell, its contents are replaced with:
# %load -s example2 helpers
def example2():
...
The same technique could be used for an external file solutions.py to reveal solutions to exercises.
@drphilmarshall suggested using
%load file.py
as a way to move large blocks of dense code into external modules and then optionally display them. Try this out and look for opportunities to improve the flow of a live tutorial with this technique. This method can also be usesd to reveal the solution to an exercise.The text was updated successfully, but these errors were encountered: