Volume Number: 21 (2005)
Issue Number: 3
Column Tag: Programming
by Christopher Roach
A Gentle Introduction to the Python Programming Language
I know what you're thinking. "With all of the languages out there why would I ever want to learn another
one?" Well, if you've never used Python, and you've never had any desire to, then I'm sure this very
statement can be found rolling around in your noggin at this very moment. But wait--hold on just a
minute--there are several reasons for learning Python. For instance, in the essay "The Python Paradox" Paul
Graham states one of the most important reasons for learning Python. In it, he states simply that "...Python
programmers are smart."
Well, I'm not sure about you, but for me, the sheer fact that Paul Graham considers Python programmers to
be of a higher intellectual caste is reason enough to learn the language. (In case you couldn't tell, I'm a
big fan of Paul Graham's essays and his insights into the hacker community.)
Nevertheless, if you haven't found yourself totally convinced by Dr. Graham's musings that good hackers
prefer Python, you may want to read on just a bit further. The rest of this article promises to go over
several of the reasons why you would want to add Python to your programming toolbox.
We'll start with a short description of the Python language, and what advantages it holds for its users.
Then, in the latter half of the article, we'll take a look at several code editors and IDEs and even one stand
alone RAD tool, all of which will surely help make your transition from relative newbie to Python power-user
an easy one.
Before we get started, however, if you already consider yourself to be a fairly erudite Python developer, don't turn away from this article just yet. As I mentioned in the previous paragraph, we'll be reviewing quite a few development tools that could easily help out even the most experienced Python developer. So, you may just want to skip the next section (since it mainly just synopsizes Python for the newbie) and proceed onto the rest of the article where you'll hopefully find some nice new toys to play with.
However, if you have no previous Python experience and you find yourself interested in learning what all the hype surrounding Python is about, go ahead and read on--the next section is just for you.
Let's start with a good overview of Python. Python is an interpreted, dynamic, object-oriented programming language. Sounds great right? But what exactly do all those terms mean to me? Well, let's look at the attributes mentioned above and discuss the benefits each provides.
First, Python is an interpreted language. Unlike many traditional programming languages in wide use today--such as C, C++, and Java--Python is not compiled. This has many benefits to a programmer. To start with, it means that programs can be written and executed instantly without a costly compile step. This cuts down on the edit-test-debug cycle by allowing us to immediately see the results of changes to our code. It also means that we can write very small programs interactively (i.e., each line of code is executed as we type it to give us immediate feedback). What this means is that any small task that calls for a short throwaway program can be created on the fly (I love this feature). Plus, learning new features of the language is a snap since all you have to do is open a command prompt and run the interpreter to execute, on the fly, everything you type rather than going through the arduous process of creating a file, adding the code, compiling it, executing it, fixing it, etc.
Second, Python is a dynamically typed language. A dynamically typed language is one that does not need to know the data type of a variable at compile time, but rather it can determine the data type during the runtime of the application through the context in which it is used. Thus, when using Python, the time consuming practice of declaring all variables is avoided. If you need a variable to hold a string, simply create a variable and assign a string to it. There's no need to tell the compiler what the data type of your variable is, it can figure it out on its own. This leads to a much faster development cycle.
Finally, Python is an object-oriented language. Now, since this article assumes that the reader has at least a small knowledge of programming (and hasn't been living under a rock in the recent computing past), I'll spare you the details of the benefits found in using a language possessing object-oriented capability. I'll just say quickly that, unlike other languages, such as Perl and C++, Python was developed from the ground up with the object-oriented paradigm in mind. This means that creating a fully object-oriented program in Python is much more natural than it is in other procedural-turned-object-oriented languages.
Well, that's a nice description, but what else can Python do for me? Glad you asked. A few of "my" favorite reasons for using Python are readability, portability, and a large selection of libraries and active developers. Let's take a look at what each can do for you.
The first advantage I've named could seem to be either a curse or a godsend at first, but most users of Python have grown to think of it as the latter once they got used to it. Python has a rather quirky way of designating blocks of code that will probably drive you nuts at first if you are a C/C++ or Java programmer by trade. It designates code blocks without the use of braces or begin-end statements. Instead, Python uses indentation. This may seem like a very annoying trait at first, however, once you've had to work on a project with at least one other coder and tried to read their ill-formatted code, you'll be praising this feature in no time.
Python's use of indentation-designated blocks of code is efficient, clean, and understandable, plus it makes sure that everyone on a programming project follows an identical indentation scheme. It may take a few short programs, but once you've gotten used to it, and you use a good editor like Emacs that takes care of the indenting for you, you'll find you actually produce code a bit faster now that you are able to forget about matching up braces or typing out the words begin and end all of the time. Thus, Python ensures a certain amount of consistency across developers and provides a certain amount of brevity for the single developer.
Next, and one of my absolute favorite features of the language, is the availability of the language on nearly every platform. At home, I do all of my development on an Apple Powerbook running Mac OS X v10.3 (Panther). At work, I do all of my development on a Dell either running Windows XP or Redhat Linux. On all of these platforms I am able to use Python as my scripting language of choice. What this means is that a program I write at home can be ported over to my work computer without any fuss, and vice-versa. Throw in the availability of several cross-platform GUI libraries for Python, and you have a complete solution for developing applications that can be used on virtually every popular operating system and computer architecture in use today. This also means that programs you develop will be available to a larger audience, than say; a program developed using Objective-C and Cocoa.
The final advantage I've listed declares quite a bit in one statement. First, you should know that Python has been around for a while. It's been around long enough to have developed a strong and very loyal following (in fact, the computing powerhouse, Google, asks for Python experience in nearly all of their employees. Now that's an endorsement), but just short enough to still be considered a modern programming language.
Initially developed around 1990 at the CWI (a research institute specializing in mathematics and computer science in the Netherlands) by Guido Van Rossum, the language has been widely accepted by the programming community, especially those involved in system administration, the Open Source community, and the hacker community (as described by Paul Graham in his essay "Great Hackers "). The language has a very strong following and because of this, it is always evolving and gaining new libraries and abilities. It is definitely not a dead language, and in fact, it is currently under the control of the Python Software Foundation, a group that is dedicated to the advancement of open source technology related to the language. It's also nice to know that at the helm of this foundation is the creator of the language himself. This amount of support ensures that Python has a large community of developers available for help and questioning as well as libraries for nearly every need imaginable.
So, now that you have a good overview of the Python language and what it can do for you as a developer, you may want to take the time to actually learn the language. If you're cheap, or perhaps just broke, you're in luck. Just like any other language popular amongst hackers, Python has quite a large number of online tutorials, references, sample programs--you name it. Just about everything you need to learn the language can be found for free on the internet. You'll definitely want to check out the tutorial on the main Python website [http://www.python.org/doc/2.3.4/tut/tut.html] and after you've got the basics down, you may also want to check out the Python Cookbook [http://aspn.activestate.com/ASPN/Python/Cookbook/] to find some nice recipes for your own development.
I'll go ahead and make the assumption that since you've read this far, I've already piqued your interest enough to make you want to go out and learn the language. However, if you're going to learn Python you might as well do it in style. That's where the rest of the article comes in.
The remainder of this article is going to go over some of the code editors and IDEs that you can use on OS X to develop your Python scripts. So, get out your laptop, or fire up your desktop, grab yourself a nice cup of coffee, or whichever caffeinated life support--err...I mean beverage--you drink regularly, and get ready to start some downloading. After all, you don't want to be the last one on your block still using TextEdit to write your Python scripts, now do you?
However, Before We Get Started...
Before we get started with our journey, however, we need to make sure that we are all starting on the same page. The Mac OS, from about v10.2 (Jaguar) and above, has come with a preinstalled version of the Python programming language. However, at last check, the version that came with the operating system was v2.2. So, before we get started with our journey into the wonders of Python on the Mac, we need to download and install the latest version of the Python programming language (v2.3 as of this article's writing) which can be found at the MacPython website [http://homepages.cwi.nl/~jack/macpython/].
Once you've got the latest version of MacPython installed on your system, you're ready to start playing around with Python. But, before we can do that, there is still one last problem in need of a resolution.
Many of the IDEs that we will be reviewing in the next section of this article were developed in Python using the wxPython GUI library. So, in order for us to use these applications we're going to need a copy of wxPython installed on our system
You can download a copy of the most current library from its homepage [http://wxpython.org/], however, you'll find that if you install the most up to date edition of the library, the Boa Constructor IDE that we will discuss shortly, will not run. In order to make use of Boa, you'll need an earlier version of wxPython: wxPython v126.96.36.199. To get a copy of this version you'll need to download it from the Sourceforge repository at the following address: http://sourceforge.net/project/showfiles.php?group_id=10718.
Luckily, the install is extremely easy, since, both the current version (v188.8.131.52) and the earlier version (v184.108.40.206) have installer packages made for them. All you have to do is download the package at the aforementioned URL and follow the steps to get it installed.
Once you've got the current version of MacPython and wxPython v220.127.116.11 installed, you're ready to start experimenting with the myriad of development tools available to the Python programmer.
Code Editors And Integrated Development Environments
Well, now that we have downloaded and installed a copy of MacPython and the wxPython GUI libraries on our system, we should be able to try out some of the development environments available for Python. Several possibilities exist for the Python developer looking for an IDE or a simple code editor on the Mac and this section introduces quite a few of each.
For anyone who's looking for a simple code editor for Python, the choices are nearly limitless and most are quite good. In this category, we'll look into a couple of classic and powerful editors that already come with your system: Vim and Emacs. However, if your interests lie in finding a full IDE comparable to Apple's Xcode or Microsoft's Visual Studio, Boa Constructor, or the Wing IDE should suffice. We'll cover both of these options and we'll even look into ways that we can use Xcode as our Python development environment. Finally, we'll review a RAD tool that allows us to quickly develop wxPython-based GUIs without writing a single line of code. As a bonus, the latter application should be useful to any Python developer using the wxPython GUI library regardless of which code editor or IDE they've chosen to use.
So, lets get started by taking a look at a couple of options for those of you just wanting a simple code editor that supports Python development with simple features such as syntax highlighting and perhaps automatic indentation. The first section covers the powerful and popular editors Emacs and Vim and discusses how to get them to grok Python.
Emacs and Vim
If what you're looking for is a simple code editor, then you'll find that a few come already installed and ready for work on your computer right out of the box. Mac OS X comes with two very popular and very powerful command line editors: Vim and Emacs. Both editors understand Python and can be coerced into providing syntax highlighting with very little effort.
I fired up Vim for the first time the other day just to try it out and see if it worked with Python, and it did perfectly. In fact, all I needed to do to add syntax coloring was to type :syntax on while in command mode, and Voila, beautiful syntax coloring right from the command line. You can also add that line (sans the preceding colon) to the .vimrc file in your home directory if you wish to always start the editor with syntax coloring turned on.
While many developers love Vim and wouldn't be caught coding with anything else, I personally find it to be a bit daunting. I learned to program on Emacs from the command line and I still prefer Emacs to just about any other code editor. It's powerful, easy to use, easy to customize, and it comes free with Mac OS X just as Vim does. Also, just like Vim, if you prefer to see your code in color, you'll need to turn on syntax highlighting by hand.
To turn on syntax highlighting in Emacs, you'll need to type M-x global-font-lock-mode once you've started the application. (Note: By M-x, I mean to use a combination of the Meta key and the x key. For the Mac, the Option key or the Escape key can act as the Meta key while in Emacs.) Otherwise, if you like to open your editor with syntax highlighting already turned on, you can add (global-font-lock-mode 1) to the .emacs file in your home directory. Make sure you include the surrounding since Emacs uses a version of the Lisp language, called elisp, for configuration and scripting.
If you've added the global-font-lock-mode line to your .emacs file and syntax coloring still doesn't seem to be working, it may be because you forgot to add the .py extension to your file and you've left out the optional she-bang line at the top of your script, thus the editor has no way of knowing that you just opened a Python file. The same is also true for Vim. You should be able to remedy the problem, however, by either adding the she-bang line to the top of your script telling the shell which program is used to run the script, or by adding the .py extension to your file's name. If you choose the former option, the she-bang line should look something like this: #!/usr/bin/python. Where, /usr/bin should be replaced with the path to the Python executable on your system, which you can find by typing in which python in the Terminal application.
However, if you have your .emacs file setup correctly and you also have the appropriate extension and/or she-bang line and yet Emacs still does not work correctly, it may be because you don't have a definition for a python-mode on your system. You may need to download an elisp file that defines the python-mode and install it. To do so, download python-mode.el from SourceForge.net at http://sourceforge.net/projects/python-mode/ and add the following lines to your .emacs file in your home directory. (Note: make sure to use the correct path to the location of your python-mode.el file in the load-file command, rather than the one I've supplied here.)
Listing 2: Adding python-mode to Emacs
The following lines create a variable that holds the location of the python-mode.el file, loads the new mode into Emacs, and associates the .py extension with that mode.
(autoload 'python-mode' "python-mode" "Python mode." t)
(add-to-list 'auto-mode-alist '("\.py" . python-mode))
Now, I realize that not everyone enjoys using command line editors. Many programmers have grown up in a Windows environment where the idea of doing any serious work from the command line is laughable. To those of you who feel this way, I would like to suggest that you still consider giving these command line editors a try. Remember, your working with an interpreted scripting language when working with Python, and for that reason, you will find yourself wanting to use it for several small throwaway programs that will quickly run from the command line to accomplish a task or two and then be destroyed. When writing quick and disposable programs, I find it's generally fastest to develop from the command line rather than resorting to a full IDE. That said, it's not a bad idea to use an IDE when developing larger, more complex programs rather than quick scripts. For those of you who wish to use a complete IDE for those tasks, I've listed a few choices below.
Probably the most popular and most powerful Open Source IDE for Python (at least of the IDEs that work on OS X) is the Boa Constructor IDE. This program is a fully loaded IDE, with project management and a RAD tool for generating GUI code (wxPython code only). But, as good as that sounds, I did find a few problems when working with it.
First, I found it to be a little slow and unresponsive. I'm running this program on a G4, 1.25Mhz PowerBook with 1GB of RAM, and yet it still feels a bit sluggish. So, I don't see this as being a productive environment for anyone not running on a top-of-the-line Mac (preferably a G5-based PowerMac).
Second, the way the GUI was constructed disturbed me a bit. Basically, you had three main windows when starting a project, all of them disconnected from the other. So while you were working in the main editor window, the rest of the windows would gray themselves out and move to the back. This made it feel like three separate programs rather than one. There may be some way to resolve this, by turning on docking or something, but I was unable to find a way and it just left me frustrated.
Finally, Boa Constructor is written in Python using the wxPython GUI toolkit, which was our reason for download and installing the wxPython library in the last section. However, Boa Constructor does not work with the latest release of wxPython, which at this writing was v18.104.22.168. Instead, you have to download and install v22.214.171.124 of the wxPython GUI library (just as we all did during the introduction) in order to run the IDE. This is of course a minor setback and I believe that work is currently being done to update Boa to the newest release of wxPython, but for the time being you're stuck with the previous version and it is a bit annoying.
Figure 1 - The Boa Constructor IDE
In short, Boa is about the only choice you have if your looking for a full-fledged, batteries included IDE written specifically for Python, with a RAD tool and all. However, with its sluggish response and unfriendly UI, I find myself reticent to recommend it to anyone just yet. I simply feel that it's not quite ready for prime time.
Nevertheless, if you're running a top-of-the-line machine with plenty of memory and clock cycles to spare and you want a full and powerful IDE, you may as well give it a try (after all, it is free). But, for the rest of us without the means to by a dual processor PowerMac G5, I'll press on and discuss some editors that I do find worthy of looking into a bit closer.
If you're looking for an IDE that's developed specifically for Python and runs like a professional tool should, then you can look no further than Wingware's Wing IDE. In the previous section I said that Boa was probably the most powerful IDE that I'll cover in this article. Well, personally I prefer the Wing IDE to Boa, and I find it to be nearly as powerful as the Boa IDE. However, one area in which the Wing IDE falls just a bit short of the Boa IDE is in its exclusion of a RAD tool for GUI development. With that said, I do believe that what the Wing IDE does...it does better than Boa, and for that reason I prefer it to Boa, or for that matter, to any of the other IDEs I've tried for Python. Plus, if you absolutely must have a RAD tool, you can always use the Wing IDE in conjunction with the wxGladeOSX GUI designer that we'll be taking a look at shortly. But, before we get to our free RAD tool, let's take a closer look at Wingware's Wing IDE.
During the time that I spent with the Wing IDE, I found it to run smoother, look better, and just feels a bit tighter than the Boa Constructor IDE. Wing IDE has code completion (one of my big requirements when using an IDE) that actually works, in other words, it helps you code rather than get in your way. Nevertheless, Wingware's IDE does have a few problems that I'll go over in the next few paragraphs.
First, the application utilizes X windows for its window management, so it will need X11 (or some other implementation of X windows) to run. Though I prefer to run my applications in Apple's native Aqua look and feel rather than using X11, the IDE still looks really great. Unlike most programs using X, it actually looks as if belongs on OS X.
Second, just like Boa Constructor, the Wing IDE was developed with Python and wxPython, and just like Boa Constructor, it runs a little slow. Surprisingly though, this one doesn't run nearly as slow as I would have expected considering the complexity of the program and of course the fact that the program is being actively interpreted rather than ran as a precompiled executable. So, while it is definitely slower than say, a compiled Objective-C program using Cocoa, it's not so slow as to make it unusable.
Third, the project management features seemed a bit clumsy when compared with other IDEs I've used. For example, when I created a new project, I was not presented with a wizard to choose the location and name of my new project, as is the case with most IDEs. Instead, I had to choose Save Project As... from the Project menu--after I had already created the project--and rename the project and choose its location. Plus, you'll need to create a folder for your new project as well, otherwise you'll find your files scattered all over the directory in which you created the project. Also, when adding a file, you're confronted with the same scenario as when creating a project. Once again, you must choose Save As...from the Project menu to designate a name and location for the file--after you've already created it--and you have to run through the entire directory structure again to place it in the same location as the project rather than the default being to place the file in the project's folder. Once you've created your file, named it, and chosen its location, it is still not yet part of the project. You must choose Add File... from the Project menu to finally add the new file to your project. None of this is especially hard to do, but it's not the most intuitive or efficient process and it's definitely not a very user-friendly design.
Finally, the Wing IDE, unlike all of the other editors and development environments I'll mention in this article, is not free. Luckily, it doesn't cost very much for a hobbyist just wanting a decent IDE on which to develop their Python applications. In fact, as of this writing, the personal edition of the IDE could be purchased for $35, and if you definitely must have an IDE, I see no reason why the Wing IDE couldn't fill that void for you.
Figure 2 - The Wing IDE
All in all, this is probably my favorite of the IDEs developed specifically for the Python programming language. I wish it ran just a bit faster, and it would be nice to see someone develop a Cocoa based Python editor, but until that happens, I would recommend this IDE to anyone searching for a nice Python development tool. Plus, you can download it and try it out, fully functional, free of charge for up to ten days. So, why not take it out for a spin and make your own judgment call on whether or not it's worth the money.
Eclipse With PyDev
Eclipse is many things: a generic development environment, Java IDE, platform for tool development, GUI library--the list goes on and on. In fact, Eclipse is so large that several publishers have released entire books on just using it effectively. For our purposes though, we can just think of Eclipse as an IDE that can accommodate any language for which an extension has been developed. Python happens to be one of those languages, and PyDev is the name of the extension that provides Eclipse with the ability to grok Python.
PyDev tags itself as a complete development environment for Eclipse. It consists of three plugins. The first is the editor plugin and it supplies the user with helpful features such as syntax highlighting, smart indentation, and a whole list of the usual suspects. It claims to support code completion and refactoring as well, however, in my tests I found both of these features to be somewhat buggy. One feature of the editor plugin that I did find to be very helpful was its ability to capture syntax errors on the fly. For instance, if I tried to concatenate two strings, but I accidentally left out the '+' sign, the variable containing the second string would be underlined with a squiggly red line (reminiscent of most word processor's spell checking feature) to alert me that my syntax was incorrect and that the interpreter was expecting something other than just two operands, one right after the other.
The second plugin is the debugger. This plugin provides Eclipse with your typical code debugger, providing the user with a way to step through their code using breakpoints and look at variable values and so forth.
The third and final plugin of the PyDev development environment is the help plugin. This supplies the user with some brief, Eclipse style, documentation for PyDev.
With regards to being a proper development environment, the PyDev and Eclipse combination seems to be a formidable solution. If you're dead set on using an IDE to develop your Python applications rather than a code editor like Emacs or Vim, and yet you don't want to spend the money to purchase the Wing IDE, then I would recommend this one over any of the others I've reviewed in this article. I haven't worked with this setup for very long (as I said earlier, my favorite environment is Emacs right now) but I have used Eclipse quite extensively in the past with Java (in fact, Eclipse is my IDE of choice when doing Java development) and I have found it to be a very good IDE. Plus several major companies in the software industry have been trying to standardize on Eclipse for their IDEs. You know when companies such as IBM and Wind River (creators of the popular embedded OS VxWorks) are using Eclipse that it must be a good environment.
The main thing to remember is that PyDev is currently in version 0.8 (it has not yet reached version 1.0), and as such, it is still in its beginning stages. So, it's a little rough around the edges. Nevertheless, what it does...it does well (with the exception of features that are still in their infancy), but it does need some polish before it will feel like a fully functional Python development environment.
Finally, I want to go over a couple of ways that you can make use of Apple's Xcode in your Python development. If you choose to go with this option you'll find that you have two schools of thought: 1) you can create pure Python applications (i.e., cross-platform, not dependent on Cocoa), or 2) you can create OS X native applications using PyObjC with Cocoa. We'll first cover creating and running a platform-independent, pure Python application, and then we'll look into what PyObjC is, and what it can do for us.
When playing around with Python one day, I finally reached a point when I thought; hey, wouldn't it be great to develop in Xcode. After all, I've done some development with Xcode, mainly just teaching myself AppleScript, but I was, nonetheless, quite impressed with the environment. It was fast and efficient and, unlike other IDEs, it didn't get in my way when I was programming. So, I started searching the web for a way to setup Xcode for Python development other than just using the PyObjC bridge to develop Cocoa based applications. After a bit of looking, I eventually stumbled across a site called pyx (Python on OS X) and it had some directions for setting up Xcode for this very task. In the next couple of paragraphs I'll share with you a quick summary of the information I garnered from that site. (By the way, the webiste's URL is http://ulaluma.com/pyx/, it's worth a look every now and then to see if any new and useful information has been reported.)
First, let's start off with developing a Python command line application. The process is pretty simple. You basically just need to setup an empty project (since Xcode does not directly support Python development) and create a custom executable to run your application. So, if you follow the steps I've detailed below, you'll be up and running in Xcode in not time.
1) Choose File->New Project to create a new Xcode project
2) Make sure you select Empty Project as the type of project to create
3) Choose where to save the project, name it, and click Finish
4) Add your main file to the application
5) Choose Project->New custom executable
6) Name your custom executable and type in the path to the python executable on your system (you can type which python in the terminal window to get this information)
7) Double click on the custom executable you created to open its main information window.
8) Click the arguments tab and click the '+' button to add a new argument to the list.
9) The new argument should be the complete path to the main file of your application (you can either find this path using Finder or the Terminal application)
10) Choose Debug->Run Executable or Press opt-command-r to run the application.
Running a Python application that uses the Window Manager is essentially the same as running one from the command line, however, we need to tell Xcode to use pythonw instead of python (pythonw is needed to run a Python script that makes use of the Window Manager, i.e., a GUI-based application). This is where we run into a small problem. It seems that Xcode only wants to run a binary executable, which python is, and pythonw most definitely is not. Since pythonw is a simple shell script we can run it by passing it and the file we wish to execute as arguments to the sh program. Using this method, our new executable path should look something like the following: /usr/bin/sh /usr/bin/pythonw /path_to_main_file/filename.py.
Another way that we can run our GUI-based application is to put the full path to the executable that is
referenced within the pythonw script into the executable path of our custom executable that we created in our
Xcode project. If you prefer this method, you'll first need to get the location of the pythonw script, which you can do by typing which pythonw into a Terminal window. Once you've got the location of the pythonw script, you'll need to open the script with your favorite editor or display the contents of the script with the cat program and copy and paste the full path to the Python executable from the pythonw script into the executable path of the custom executable we created to run our application. Once you've done this, you'll be able to run your GUI-based Python programs directly from Xcode.
If you like Python and you don't really care to create platform agnostic applications, you may find that developing Python applications with PyObjC is the most logical environment for you. PyObjC is an Open Source project that provides a bidirectional bridge between Python and Objective-C. Thus, Python programmers have a way of accessing the classes of Apple's Cocoa Framework through this bridge. One of the most important uses of this is to provide the Python programmer with access to the Cocoa GUI classes allowing him/her to write OS X native, GUI-based applications in pure Python.
My experience with PyObjC has been promising, though I still believe that it needs a few more iterations before reaching the usability I prefer in a development environment. For example, I wish it were possible to generate the python files from Interface Builder as you can for Java and Objective-C rather than going to the command line to do so. Small gripes such as this aside, I did enjoy developing applications using PyObjC. I found it to be very usable, very stable, and very easy to install. In fact, binary installers are available for both Jaguar and Panther editions (v10.2 and v.10.3) of OS X and can be downloaded from the projects main website [http://pyobjc.sourceforge.net/].
If you're planning on developing applications for other platforms as well as OS X, then obviously this is not the option you should go with. However, if you enjoy programming in Python and you're looking for a way to use it to develop OS X native applications, or if you're just looking for an alternative to Objective-C, then PyObjC may just be perfect you.
Before we close out our discussion of code editors and IDEs, I wanted to go over one final option that is neither code editor nor IDE, but it does seem to fall into a similar category. The wxGlade designer is a RAD tool that can be used to design GUIs for your Python applications using the wxPython library.
The application was created using Python and the wxPython GUI library. It can be used to rapidly construct a graphical interface using the drag-n-drop methodology that other popular RAD tools use. Once the GUI is completed, wxGlade will output the code used to create the GUI. This code can then be plugged into your application and you can then go about adding the code that does the actual work saving you countless hours writing the code that creates the applications GUI.
The designer isn't just limited to producing code for Python, however. The wxGlade GUI designer also produces wxWidgets code for the C++ and XRC (an XML based code format) languages as well. This means that, should you ever become interested in using your knowledge of wxWidgets to develop cross platform applications based on another language such as C++, (say, if more speed is needed) then you'd already have the ability to do so. So, basically more bang for the buck--nice, eh?
The wxGlade GUI designer was based upon Glade, the GTK/Gnome GUI Builder. It's definitely not the most intuitive GUI development tool to use, so it will take a bit of training to become an expert with it, but it's free, and once learned, it does speed up the process of writing a GUI quite a bit. Also, it has a very simple install since a binary (called wxGladeOSX) has been created and can be found at the WordTech website [http://www.wordtech-software.com/wxglade.html].
Figure 3 - wxGladOSX With Code Displayed in XEmacs
As the title would suggest, this article was meant to be a very gentle introduction to the Python language and to what Python has to offer Macintosh developers. Hopefully, if I've succeeded in my job, you'll come away from this article with an interest in learning Python and you'll be armed with a whole slew of development environments to aid you in the process. If this is the case, make sure that you tune in for my second article, which promises to probe deeper into the tools available to the Python developer on OS X.
Unlike this month's article which was geared towards Python newbie's, next month's article will be geared to those of you already employing Python in your development routine. Those of you who fall into this group, will be introduced to several libraries that will make your use of Python easier and more effective.
So, until then my new Pythoneers--best wishes in your Python development, and happy scripting.
Bibliography and References
Graham, Paul "Great Hackers" May 2003, http://www.paulgraham.com/pypar.html (15 Nov. 2004).
Graham, Paul "The Python Paradox" Aug. 2004 http://www.paulgraham.com/pypar.html (15 Nov 2004).
Christopher Roach recently earned his MS in Computer Science from Virginia Tech and currently
works as a software engineer in Florida's Space Coast. On the weekend he tries to find time to write articles
on Macintosh programming and do battle with insanely powerful hurricanes, while still trying to preserve some
semblance of a life. If you have questions or comments on the article, you can email him at email@example.com.