Python

I’ve decided I need to become a programmer again. As an undergrad, and to a lesser extent as a grad student, I wrote code all the time. But since I started doing research, it’s been pencil-and-paper almost all the way through, with occasional dips into Mathematica or plotting programs.

That must end, so I’ve decided to learn Python. I just need something simple for number-crunching and graphics, and everyone in the know seems to have nice things to say about the language. (Secretly I would like to play around with genetic algorithms and cellular automata, but I’m not going to admit that.) I tried to get Fortran, my previous language of choice, up and running on my Mac … it didn’t go well.

So… any tips? Pointers to well-written resources and tutorials (online or in print) would be especially helpful. Keep in mind that the target audience is an aging theoretical physicist who hasn’t programmed in 20 years, and for that matter has been pretty much command-prompt free (working on my Mac) for the last five.

The things I admit in public on this blog, sheesh.

94 Comments

94 thoughts on “Python”

  1. Intel Fortran is available for the mac, and descends from good old DEC Fortran. It’s not free, but they offer academic pricing.

    Octave is a free version of Matlab, useful for quick one-offs and graphs.

  2. I know it has been mentioned before but Software Carpentry is a very nice resource, I use all the time. It has very concise and useful introductions on a number of every day computer problems.

  3. If you want to make great graphs and crunch numbers, I highly recommend R rather than Python. I love Python, and use it for developing games and experiments, but R has better graphing packages, and has implemented math functions more intuitively (and efficiently) than Numpy, IMHO.

  4. Python is a horrible programming language. Seriously you are a smart guy you could learn C in about the same amount of time and what you learn would be applicable to pretty much any language. Alternatively you might want to consider learning how to write Matlab scripts. The downside to that is the cost of a Matlab license. Maybe your University could provide you a license? Matlab is excellent for number crunching and plotting and its easy as hell to learn.

  5. I would add that if you do use emacs already, the ipython package,py-shell, and the community python-mode (not the one shipped with emacs) make a very nice IDE

    I also nth the main python docs as a resource.

  6. All you really need is a simple EXAMPLE of Python code which does something close to where you want to start – ie displays a basic cellular automata and evolves it according to some basic rules. Together with instructions how to get this running on your Mac (if that’s what you’re using)

    You could easily work out how to adapt it to more advanced stuff by perusing docs suggested in various links above (well, I mean it’s “easy” compared to understanding modern physics papers)

    So if you explain a very basic starting point you’d like, myself or someone else should be able to post code. Otherwise just google for a simple example, and find a few free hours over several weekends to experiment 🙂

  7. we use REALbasic for our medical research apps. but we are gui people first and algorithm second. perhaps a REALbasic /python/R mix might be good for your enjoyment Sean

  8. I’m an observational astronomer, but we use python all the time, for everything from scripting massive pulsar survey processing jobs to analyzing X-ray observations to simulating pulsar timing noise. I’ve got a blog where from time to time I do a sort of “worked example” of solving some (usually) astrophysical problem with python, that you might find useful as a more apropos example.

  9. Python is a good way to go. Here is a crazy thought. For something completely different there is Javascript. The advantage to that is that you could easily publish Javascript programs on web browsers. However, Javascript environments are probably harder to work with than Python.

    Someone else may point you to tools that allow you to publish Python scripts onto browsers too.

  10. I would also recommend Javascript. Combined with html and css (which you must already work with a little on this blog) you can do just about anything and have it ready to share online. Make sure you look at jQuery (a javascript set of functions for doing some fancy stuff and making basic stuff easy). Javascript, as one of the languages of the web, is by far the most well documented (since the internet is very vain and loves to talk about itself – it’s self documenting).

  11. Sean,

    Python is excellent, and scientists use it a lot. If you Google python applications, you will get lots and lots of app written by scientists.

    Ruby is also great, as well as Ruby on Rails for those who want to do web development.

    By and far the best and funniest programming book ever is Poignant Guide to Ruby:
    http://mislav.uniqpath.com/poignant-guide/book/

    Read some of it even if you have no interest in Ruby programming. It’s hilarious and a great model for making tech material fun! Plus, it’s free!

    Dana

  12. Dear Sean,

    Fortran was your previous “language of choice”? Good heavens. That language scares the bejezus out of me.

    About Python. The problem with Python is that there are so many versions 2.5, 2.6, 2.7 and now 3.x. And having installed a version you have to install all the modules for that version all over again. Then when you’ve gone through all that you find that one module doesn’t work with the Python version you installed, so you start all over again with a different version …

    Enthought’s Python Distribution (built around Python 2.7) (EPD) – which is free for academic use, btw (!) – has solved these problems for me. It contains every toolset the modern physicist could need. All of Scipy, Numpy, IDLE, Mayavi, you-name-it, EPD has it.

    You’ll probably need to install OpenGL and PyQt4 separately if you want to do some serious graphics programming. OpenGL is straightforward enough. PyQt4 is extremely tedious but straightforward to install. But its worth the effort. You’re left with the Python bindings for Nokia’s Qt api which is far superior to wxWidgets and other alternatives for building GUI apps. EPD + PyQt4 + OpenGL rocks!

    Good luck on your Python adventures,

    Deepak

  13. I had the same problem – finding good python resources. But I fought my way through it and have quite a few self-written sample programs I would be happy to zip up and send you.

Comments are closed.

Scroll to Top