Hi Reader,
Wherever you are in the world today, I wish you safety, health, and happiness! ๐
โUnofficial Python glossaryโ
This guide was written by my pal Trey Hunner, and itโs the single best source Iโve found for clear explanations of Python terms and concepts. I use it to learn new things and to double-check that my teaching materials are correct!
Back in tip 24, I introduced you to IPython magic commands, which are special commands that you can use in Jupyter.
You learned about line magics, which start with % and apply to one line of code:
You also learned about cell magics, which start with %% and apply to an entire cell:
Today, Iโm going to introduce you to 4 more magic commands that are great for saving, displaying, and running code!
Letโs pretend that youโre working in a large Jupyter notebook and you come up with a brilliant new function:
You want to save this function to reuse in other notebooks. Without leaving Jupyter, you use the %%writefile cell magic to save just this function to another Python script:
And now your function is preserved in a separate file!
Weeks pass, and youโre working in a new notebook that could benefit from this function. You want to remind yourself whatโs in the function, so you output the file contents using the %pycat line magic:
If it needed some edits, you could use the %load line magic:
Running that command loads the contents of the file into the cell (but does not run it) so that you can make those edits:
But in this case, the function is perfect as-is. Thus you use the %run line magic to run the existing file:
Our function is now available for use in this new notebook:
Key takeaway: With this workflow, you can save and reuse code blocks without ever leaving the Jupyter environment!
By the way, %run even works with notebooks! For example, if you had this notebook called drinks.ipynb:
You could run the entire notebook from another notebook, and just see its output:
Key takeaway: You can build a series of smaller notebooks, and then run them all from a โmasterโ notebook that only displays the output (and hides the underlying code).
If you enjoyed this weekโs tip, please forward it to a friend! Takes only a few seconds, and it really helps me reach more people! ๐
See you next Tuesday!
- Kevin
P.S. Which came first, the chicken or the egg?โ
Did someone awesome forward you this email? Sign up here to receive Data Science tips every week!
Join 25,000+ intelligent readers and receive AI tips every Tuesday!
Hi Reader, This week, I've got a short tip about AI agents, followed by some Data School news... ๐ Tip #56: What are AI agents? Google is calling 2025 "the agentic era," DeepLearning.AI says "the agentic era is upon us," and NVIDIA's founder says "one of the most important things happening in the world of enterprise is agentic AI." Clearly AI agents are a big deal, but what exactly are they? Simply put, an AI agent is an application that uses a Large Language Model (LLM) to control its...
Hi Reader, Last week, I launched a brand new course: Build an AI chatbot with Python. 120+ people enrolled, and a few have already completed the course! ๐ Want to join us for $9? ๐ Tip #55: Should you still learn to code in 2025? Youโve probably heard that Large Language Models (LLMs) are excellent at writing code: They are competitive with the best human coders. They can create a full web application from a single prompt. LLM-powered tools like Cursor and Copilot can autocomplete or even...
Hi Reader, The Python 14-Day Challenge starts tomorrow! Hope to see you there ๐ค ๐ Tuesday Tip: My top 5 sources for keeping up with AI I'll state the obvious: AI is moving incredibly FAST ๐จ Here are the best sources I follow to keep up with the most important developments in Artificial Intelligence: The Neuron (daily newsletter) My top recommendation for a general audience. Itโs fun, informative, and well-written. It includes links to the latest AI news and tools, but the real goldmine is...