Seeing is huge. Anything that you can do that lets you see what's happening in a system with more detail or more quickly will help you master that system. Do you want to understand how your lawn mower works? Remove the hood.
Python programming can be a pleasure, partly because it's simple to see what you're doing. If you want to understand a little snippet, you just take it to the interpreter, run it, and get an output. Edit it and get a new output.
Some effects are trickier to see because they are contextual. That is, your snippet won't do the same thing if you paste it into the interpreter as it will in the environment where it's meant to live. This is particularly true for me when I'm working with Django code, which often depends on a Django environment.
The Django shell (./manage.py shell) solves part of this problem. The Django Extensions shell (./manage.py shell_plus if you've installed the Django Extensions app) can take you further. But even then if you have code that depends on the actual location of a file, for example, you can't test it in the shell directly.
To get around that issue, I've typically done two different things in the past: 1) run the code in a test and use print statements or ipdb to get the information that I want, or 2) figure out how to reload the interpreter every time I update a module.
This post celebrates the fact that I just learned how to do 2 much more efficiently than before. So here it is -- effortless ipython reload:
Recursive algorithms can be slow because they end up solving the same little problems over and over again. To speed them up, you can use a technique called "memoization." Memoization allows algorithms go much more quickly by remembering solutions to problems they have already solved. I’m the recursive algorithm. This blog is my memoization.
Showing posts with label django_extensions. Show all posts
Showing posts with label django_extensions. Show all posts
Thursday, April 6, 2017
ipython magic: effortless module reload
Labels:
django,
django_extensions,
ipython,
troubleshooting
Friday, February 6, 2015
Django in ipython notebook
Holy moly:
I've been using ipython notebook forever. And I've been working intensively with django for many moons. I just didn't know that they two could be married so easily.
Enter django_extensions .
For the details, check out this blog post:
http://opensourcehacker.com/2014/08/13/turbocharge-your-python-prompt-and-django-shell-with-ipython-notebook/
I've been using ipython notebook forever. And I've been working intensively with django for many moons. I just didn't know that they two could be married so easily.
Enter django_extensions .
For the details, check out this blog post:
http://opensourcehacker.com/2014/08/13/turbocharge-your-python-prompt-and-django-shell-with-ipython-notebook/
Labels:
django,
django_extensions,
ipython notebook,
tools
Subscribe to:
Posts (Atom)