Learning Python – The Interactive Way

One of the nice things about programming in python is that it is free, relatively easy to use, and there is lots of support and development online. One of the downsides is that there is not a standard python package to install… you have to know about all the interesting add-on bits to get maximum usage out of python. Luckily, some enterprising astronomers and other programming-scientists have put together pre-packaged python distributions containing many of the most useful add-ons like numpy, scipy, matplotlib, atpy, etc.

In this post, I wanted to introduce you to some other interesting features and packages that may be brand-new or not yet widely advertised. I’ll also include some new books/sites for learning python.

Learning Python

  • An excellent book, How to Think Like a Computer Scientist, is now available as an online-interactive version using the python language.
  • Another interactive tutorial is based over at learnpython.org and saves you the headache of installing python if you are trying it for the first time.

Python Work Environment

  • If you aren’t hooked to emacs/vi, then you might be interested in Spyder, an interactive development environment specifically for scientific python use. I have no experience with this… anyone have any feedback?
  • The latest version of IPython includes a new interactive web-based notebook. This is roughly modeled after MatLab notebooks. I have heard the installation can still be a bit tricky, but it is a potentially powerful way to keep electronic notes or even share/work with collaborators.

 

Python Ad-On Packages:

  • SymPy – python library for symbolic mathematics
  • Mayavi – 3D plotting
  • ScientificPython – a mash-up, most of which can be reproduced using SciPy and Matplotlib
  • PyEphem – calculate astronomical ephemerides
  • PyMC – Bayesian Inference using Markov Chain Monte Carlo method
  • pIDLy – Interface with IDL via python
9 comments… add one
  • Christophe Jun 18, 2012 @ 11:39

    Useful links, but some comments:
    * The “How to Think Like a Computer Scientist” is for Python 3.0. Most of us will stay with 2.7+ till all the useful libraries are available in a 3.0 version. And even so, I guess that we’ll still use 2.N.
    * An alternative to Spyder is Eclipse+PyDev addon, very powerful.
    Cheers,
    Christophe

  • Sandy Jun 18, 2012 @ 17:01

    +1 for Spyder.
    I have found the Enthought (free for academics) distribution of python combined with spyder to be perfect.
    Setup is slightly trickier on mac than it should be.
    (Its easy enough to install spyder through macports, but making it play nice with Enthought is the tricky bit).

  • Abhi Jun 18, 2012 @ 21:05

    I’m going to sell a friend (and colleagues) blog a little (penandpants.com). He’s doing a real nice job of teaching new comers how to do stuff via python and shows how to install python in this post (http://penandpants.com/2012/02/24/install-python/). He’s involved with the astropy initiative and has some nice replacements for all you IDL programmers.

  • Erik T Jun 19, 2012 @ 14:06

    Don’t forget about Astropy (http://astropy.org)! While it’s still getting off the ground, we’re quickly making great strides, and it should probably be on the radar even of beginners.

    Another nice python editor that gently helps improve users’ programming style is NINJA-IDE (http://ninja-ide.org/). It may not be suited for raw beginners, but people moving to python with some previous knowledge with other programming (like IDL) will probably find it useful.

    @Sandy +1 also for EPD based on its simplicity, but one thing that’s annoying about the academic version: no upgrades! You have to re-install it every time a new one comes out, which eventually frustrated me enough to switch to macports…

  • Fernando Perez Jun 25, 2012 @ 16:21

    Minor correction: the IPython notebooks are mostly inspired by Mathematica, not by matlab (none of the core IPython developers are matlab users, while we all used Mathematica extensively as physicists). Here’s a history of the notebook for anyone interested in the details: http://blog.fperez.org/2012/01/ipython-notebook-historical.html.

    Since Spyder has been mentioned, I should add that spyder developers have been contributing to IPython to ensure that the integration between the two projects is as good as possible: Spyder provides a full IDE, IPython contributes the interactive component. I merged their contributions yesterday, so hopefully the next spyder/IPython releases will work even better together.

    Don’t hesitate to bug us on the ipython lists if there’s anything specific you find that we could improve. Regarding installation, we’ve tried to document it in as much detail as possible(http://ipython.org/ipython-doc/dev/install/index.html), and we’ll be happy to help out if you have any specific issues.

    • Eilat Jun 27, 2012 @ 8:18

      Fernando, I have an ipython question. Where might I get to the ipython list? Is there a forum of sorts? Can you provide a link?

      Many thanks!!

  • Fernando Perez Jul 1, 2012 @ 22:15

    Sure, our website is ipython.org. There are links on the front page to the user and development lists:

    http://mail.scipy.org/mailman/listinfo/ipython-user
    http://mail.scipy.org/mailman/listinfo/ipython-dev

  • Pit Jul 4, 2012 @ 3:23

    What version of Python is the best to start learning? Python 3.0. or Python 2.7?

  • Jessica Lu Jul 5, 2012 @ 8:43

    Much of the python astronomy software is still running on python 2.7. The upgrade process has begun but is by no means complete.

Leave a Reply

Your email address will not be published.