Archive for March, 2008

The Golden Resource List for Python Beginners

After years of being a master-of-none with programming languages, I have finally settled on one to delve deeper into: Python. I’ve been learning Python for about a month now, and it has been quite pleasurable. Although the language has been around since 1991, it has been gaining in popularity in the recent years and is used in many underlying projects at Google, Youtube, NASA, Honeywell, and the University of Maryland to name a few. It is an excellent language for a programmer of any level to pick up, and I chose it because of its versatility, clear syntax, and ease of use for transforming my ideas into a a functional and high level language.

Along the way during the past month, I have sifted through hundreds of websites and quite a few beginner books. So here, I would like to share the links that I found most helpful in my quest for Python knowledge. As far as my past experience, I’ve dabbled in many other languages such as MATLAB, HTML, Fortran, C++, Java, Perl, and so on but never really grew to master a single one or use it in my daily life.

So, without further delay, on to the list:

Before You Start With Python

  1. Python.org – I couldn’t make this list without including the main Python site. There is just a great amount of information there. Plus everything I link to can probably be found there, but my list is only those resources that really helped me along in my learning experience.
  2. Teach Yourself Programming in Ten Years – Article by the director of research at Google – A great overview of programming and learning to program, all the while avoiding the ides presented by the “Learn to program in X days” books.

Excellent Python Tutorials

  1. Dive Into Python – This is one of the first tutorials that I read about Python, and it gave me an excellent overview of the language. It really broke down the code line-by-line, but it still reads like a mix between a reference guide, a cookbook, and a tutorial. It’s a freely available book and should definitely be within quick reach as you learn Python.
  2. How to Think Like a Computer Scientist – This is by far my favorite tutorial in the entire list. I like this (freely available) book because of its plentiful and challenging exercises! I am usually picky when choosing textbooks on a new subject, and I will almost always get the book that has the most examples in it. I spent most of my time creating my own programs at the end of each chapter, and really got a feel for the language (and a nice sense of accomplishment!) at the end of each chapter. Highly recommended.
  3. Python Videos at ShowMeDo – There are over 100 videos at the time of this posting over a wide range of topics. Anything from how to open a Python session to namespaces and more. It was nice when starting out to just sit and watch someone who knew what they were doing do routine tasks, and it helped to ground basic concepts before jumping in on my own. Don’t forget to thank the creators of the videos with a comment!
  4. Learning to Program – This is one that I am going through last, because it gets into a bit more in depth discussion about basic and moderate topics. Very thorough.

Beginner Exercises and Projects

  1. How to Think Like a Computer Scientist – I just HAD to list this again, because it goes at just the right pace and the exercises are well thought out. I am convinced that I really learned about 80% of my Python basics here when I put them to practice. Learn by doing!
  2. Projects for the Beginner – Python – This is a thread on a forum with over 100 ideas for programs. Use this when you are low on inspiration but high on ambition!
  3. Python Challenge – Neat implementation of puzzles that can be solved with Python scripts. They get harder as you progress levels. You might want to hit up the Python Challenge after getting a good hold on the basics and after you have many of these other links open in other tabs. :)
  4. Useless Python Challenges – This site should be visited after you have finished all of the trivial Python exercises and projects. When you are self-sustaining on the language and eagerly looking for some projects to do, but are hitting a writer’s block for programs, go here.

Beginner Forums and Lists

  1. Python Forum – Beginners – Not a very high traffic forum, but they have a beginners subforum with 15-30 posts per day, just enough to keep you busy. I find it helpful to attack the problems that other beginners are facing. And if you come up with a good solution, post it and help others while you learn. Everyone wins!
  2. Learning Python Blog – One of the few “learning only” Python blogs. It is always good to see information shared from others while they learn. Sort of like this list. :)
  3. Python Tutor Mailing List – I only recently signed up for this, but I must say that there are some very knowledgeable and helpful people on here and it keeps the Python information coming at you via email. Seems to be quite a few students on here and you will most certainly learn something with each email thread.

Interesting Python Projects and Libraries

  1. Django Project
  2. TurboGears
  3. Google GData Python API – This is an amazing API from Google that allows you to interact with Google Calendar, Docs, Maps, Youtube, Notebook, and so on. It is very easy to install and use and I look forward to developing with this in the near future.
  4. wxPython – GUI toolkit for interface development. I haven’t gotten to GUIs yet, but everywhere I turn I see references to wxPython.
  5. matplotlib – 2D plotting library that produces very nice looking graphs. Supports many, many types of graphs and is very customizable.
  6. SciPy – A collection of Python tools and modules for use in science, engineering, and mathematics. This is the light at the end of the tunnel for me and I hope to get more involved with this library as I progress with my Python learning.

Editing Tools and Shells

  1. iPython – An enhanced Python shell that seems geared towards science, engineering, and high performance computing.
  2. TextMate (Mac OS X) – This is such an amazing editor that I must list it here. I didn’t use it at all before I started with Python, and now I simply cannot go without it. I had previously heard it described by programmers as a magical tool, but I had no idea. It does autocompletion based on previous words, syntax highlighting for a ton of languages, has a quick and easy-to-read method to execute Python scripts. It is perhaps the only non-free item in my list, but very much worth it!
  3. TextWrangler (Mac OS X) – This is what I used for a couple of years… until I discovered the greatness of TextMate a few weeks ago. TextWrangler is free though if you wish to use it.

Other Resources (References, Packages, Hosting)

  1. Python Library Reference – Huge list of explanations about Python’s Standard Library. Made to help you discover the power of Python in your everyday programming.
  2. Python Webhosting – List of webhosts that offer Python solutions on their webhost. Python can be run on most hosts via CGI, but these wiki pages explain exactly how they implement Python usability. Plus I found out about the cool idea of HCoop cooperative web hosting through this list; this is the host on which you are reading this blog. :)
  3. Python Package Index – Directory of Python packages that you can learn about, download, and use in your own programming. Don’t reinvent the wheel!
  4. Python Cookbook Code Samples – This is a directory in the same vein as the previous listing, but the solutions to problems are presented as code with user comments. As of now there are over 2000 recipes.
  5. The Daily Python URL – Just as it sounds. News about Python in compact form.

Again, while there are many, many other resources for learning Python, this is a list of my personal favorites. These are the specific sites that have been very helpful and impacting on my venture to learn Python. So while I may not have listed a particular item – I probably saw it, but didn’t get much from it at this time.

Finally, you must forgive me if I got some detail wrong. I am learning, after all! Hopefully this list will help new and moderate Python users to utilize some of the best (and free!) Python resources that others have put up for all to learn from. Thanks to those people who shared their knowledge. And have fun with Python!

Comments (3) »


How to install PyObjC, pygame, and gasp on Mac OS X for Python tutorial

I am going through the Python tutorial “How to Think Like a Computer Scientist” right now, and it is an excellent source for beginner/intermediate Python hands-on learning.

http://openbookproject.net/thinkCSpy/

However, when I got to chapter 8, my fun stopped right away. The author refers to a Python library called GASP (Graphics API for Students of Python) and gives an example and case study of a small game. The thing is, he doesn’t tell you how to install the module and it abruptly interrupts your lovely Python learning experience.

http://openbookproject.net/thinkCSpy/ch08.xhtml

I tried to use easy_install to install most of these, and it always ended up failing for some reason or another.

As I am using Mac OS X Leopard, I will provide the missing instructions for how to get the gasp module installed (and its dependencies) for anyone else who runs into this situation:

How to install PyObjC, pygame, and gasp on Mac OS X

  1. I assume that you have already installed some version of Python; I am using Universal Python 2.5 from http://www.pythonmac.org/packages/ which is a nice, easy-to-install package and has other prebuilt packages like numpy, wxPython, matplotlib, etc. ready to be installed. You can see other ways to get Python on your Mac at http://wiki.python.org/moin/MacPython/PythonDistributionsForMac
  2. You will need to install PyObjC, which is also available as a package from http://www.pythonmac.org/packages/ under the 2.5 link.
  3. Now, you will install pygame from a package (pygame-1.8.0rc4-py2.5-macosx10.4.mpkg.zip) available at http://rene.f0o.com/~rene/stuff/macosx/. This is linked from http://www.pygame.org/download.shtml
  4. Finally, we get to the part of installing gasp, which is confusing to find in itself. The FAQ page is at https://answers.launchpad.net/gasp-code/+faq/42 but the link to download is wrong. Get it from https://launchpad.net/gasp-code/+download. You will want to download the Code Release which is currently called python-gasp-0.1.1.tar.bz2.
  5. Extract the bz2 file and there will be a folder inside called gasp. Copy this folder to the /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ directory and you will be in business!

    This is the command that I used: sudo cp -R ~/Desktop/python-gasp-0.1.1/gasp/ /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/gasp

  6. Open a python session and type import pygame and import gasp to make sure that they are installed correctly.
  7. Carry on with the great tutorial linked above!

I found it odd that the beginners tutorial left out all of this information. Hopefully this will save someone the two days that it took me to find all of these links, packages, and methods.

Comments (5) »


Mac-Corrected Numerical Analysis Fortran Programs

I am taking a numerical methods course and using the textbook Numerical Analysis 8th edition by Burden and Faires:

Numerical Analysis

The book is good and has nice pseudocode examples throughout. It also has a companion website with all of the algorithms programmed in C, FORTRAN, Pascal, Maple, MATLAB, and Mathematica. For our assignments, we can use any program that we want, and I have been using MATLAB, FORTRAN, and Python as those make the most sense to me thus far in my computing experiences and are the most useful for my work.

However, the FORTRAN 77 programs on the website are programmed in such a way that they only work when using a FORTRAN compiler in Windows. At this time, my primary machine is an Apple Macbook Pro laptop, and I am using the Intel Fortran Compiler version 10.1 on OS X Leopard. When I try to compile the programs from the textbook website, I get errors. So, I went ahead and fixed the files so that they would work on with the Intel compiler on the Mac, and hopefully Linux as well.

The two problems were that:

a) The programs were trying to read and write to ‘CON’, which is a Windows specific way of writing to the command window console.

b) The programs had an extra line at the end and would crash the Intel compiler.

So, I fixed these errors in all of the programs and you can download the corrected files in .zip format from me and follow the instructions below to compile.

The original files are freely available from the author’s website here

Step 1: Download the above linked zip file of the corrected FORTRAN 77 programs

Step 2: Unzip the FORTRAN files. You will find several files with the .FOR extension.

Step 3: Run the Intel FORTRAN compiler using the command: ifort -f77rtl -o <outputname> inputfilename.
For example, to compile example 12.1: ifort -f77rtl -o alg121 ALG121.FOR.

Step 4: Make the output file executable with: chmod +x alg121

Step 5: Run the file with ./alg121

Step 6: Be sure to answer the first Y/N question with the y or n character in quotes, such as “y” or “n”

Step 7: Have fun learning numerical methods and dissecting the FORTRAN programs!

Leave a comment »