IPython Magic Functions

Both Python for Data Science for Dummies and Machine Learning for Dummies rely on a version of Anaconda that uses IPython as part of its offering.Theoretically, you could also use Anaconda with Beginning Programming with Python For Dummies, but that book is designed to provide you with an experience that relies on the strict Python offerings (without the use of external tools). In other words, the procedures in this third book are designed for use with IDLE, the IDE that comes with Python. IPython extends the development environment in a number of ways, one of which is the use of magic functions. You see the magic functions in the code of the first two books as calls that begin with either one or two percent signs (% or %%). The most common of these magic functions is %matplotlib, which controls how IPython Notebook or Jupyter Notebook display plot output from the code.

You can find a listing of the most common magic functions in the Python for Data Science for Dummies Cheat Sheet. Neither of the first two books use any other magic functions, so this is also a complete list of magic functions that you can expect to find in our books. However, you might want to know more. Fortunately, the site at https://damontallen.github.io/IPython-quick-ref-sheets/ provides you with a complete listing of the magic commands (and a wealth of other information about IPython).

Of course, you might choose to use another IDE—one that isn’t quite so magical as Anaconda provides through IPython. In this case, you need to remove those magic commands. Removing the commands won’t affect functionality of the code. The example will still work as explained in the book. However, the way that the IDE presents output could change. For example, instead of being inline, plots could appear in a separate window. Even though using a separate window is less convenient, either method works just fine. If you ever do encounter a magic function-related problem, please be sure to let me know at John@JohnMuellerBooks.com.

 

Download Site for Python

I recently received an e-mail from a reader who had a bad install with Python 3.3.4 on a laptop with 64-bit Windows 7 installed. No matter what the reader did, the installation wouldn’t work. The application would fail with an error stating that pythonw.exe was unable to start and it included an error of 0xc000007b. He had downloaded the code from https://www.python.org/download/releases/3.3.4/, which is the site mentioned on page 25 of Beginning Programming with Python For Dummies. However, downloading a copy from http://continuum.io/downloads#py34 or https://store.continuum.io/cshop/anaconda/ did provide a copy of Python 3.4.3 (not the version 3.3.4 that is used in the book) that does work on his system.

The problem with this solution is that installing a copy from this second site also installs Anaconda—a product that isn’t covered in the book. In order to work with the IDLE examples in the book, you must open a copy of IDLE in the Anaconda\Scripts folder of the Anaconda installation. You’ll likely find this folder in your personal folder of your system. If you do find that you can’t get the copy of the product from the Python download site to work on your system, try this second solution and please let me know about the issue at John@JohnMuellerBooks.com. I would strongly encourage you to try the setup found in the book, however, because using Anaconda will cause extra work for you and this book is truly meant to help someone who has little or no programming experience discover the joys of working with Python.

As a side note, I have tried the book’s source code with the latest Python release, 3.4.3 (the book was originally written to use version 3.3.4). All of the source code works on my test system, but I’d love to hear if it works on your system as well. You can obtain this updated version of Python at https://www.python.org/downloads/release/python-343/ or http://continuum.io/downloads#py34 (if you don’t mind installing Anaconda as well).

When using the 3.4.3 version of Python, your screenshots may vary some from those found in the book. All version-specific information will change, so you need to take this change into account as you read. Please let me know if you experience any problems using this updated version on your system. In the meantime, happy reading!