You've never programmed in Python before. Should you start now?
Yes. This is as sure a bet as you're going to get in the technology horse races: The benefits of the Python programming language are so many, and its costs so low, that you're almost sure to come out ahead.
Python's strength is its universality. Once you learn it, you'll find you can use it for nearly all the programming you do. Press coverage might have led you to think that it's "just a scripting language for the Web," or only used by academics. As good as Python is in those roles, you'll see below how it also does much more. Among other things, Python is: a starter language, scalable to large professional programs, graphically savvy, and it even does windows!
Are you a newcomer to programming? Python is an ideal first language. It originated in a 1980s project to design a language for beginners. Its maintainers have always shown a willingness to "do things right." The Python world understands that phrase to mean they make the language logical, simple, and inviting, even at the occasional expense of conflict with industry traditions.
Python insiders don't just talk about "outreach" to non-programmers. The Python community supports an active "Programming for Everybody" Special Interest Group. Python founder Guido van Rossum's current principal project, funded by the Department of Defense's Advanced Research Project Agency, is on the same topic.
The Python features newcomers most applaud include:
Its availability: There's no charge for using Python, and essentially identical versions are available for Windows, MacOS, Linux, BeOS, other Unixes, and many other operating systems.
Its interactivity: Once installed, a Python user can immediately interpret his work. Type a line of source code, and Python processes it as soon as you hit "Enter." That short feedback loop is especially important for beginning programmers.
Its simplicity: Guess what
does. You're right -- and you've just read your first Python program. Python minimizes unpleasant surprises and "trickiness."
current = 2000 start = 1990 elapsed = current - start print elapsed
Its power: Python developers typically report they are able to develop applications in a half to a tenth the amount of time it takes them to do the same work in such languages as C. While "power" and "expressivity" seem to have unquantifiably subjective components, experts generally agree that Python has as much or more of these good things as other languages.
Scalability is nerdspeak for "travels well and doesn't let me down." While Python is great for beginners, it also fills the needs of expert users. Other languages popular in educational settings have been scorned by working developers as too slow, incapable of connecting to existing resources, or too inflexible. Few complain about Python in these regards. Python stretches all the way from beginners' one-liners to some of the largest and most demanding computer programs. Python is in use, for example, as part of very complex supercomputer analyses of metal fractures.
We need to be careful about several key concepts in understanding Python's capabilities "on the high end." The metal structure application just mentioned uses Python in crucial ways; in fact, insiders have said that the project simply wouldn't have succeeded without Python. However, most large Python-coded programs, including this one, have a majority of their source written in such other languages as FORTRAN, Java, C, and C++.
Each of these other languages is superior in certain aspects: speed, scientific calculation, graphics manipulation. Each also has characteristic weaknesses. The search for the one true language to use for complex projects is a mistake. The more rational approach is to find the right mix of languages and "glue" them together with Python. You will end up with more efficient, error-free, and maintainable code by using Python to combine the best of each of these.
Because it plays nicely with other languages, Python doesn't create dead-ends. While this idea is hard to make precise, experienced programmers recognize it. Programs begun in Python have good lives; they don't hit limits in speed or algorithmic sophistication which cause them to stagnate. They grow with your needs and your abilities. I almost always feel safe in choosing Python for a project. Even when information turns up during the life of the project that was unknown at the beginning, I have confidence that Python's flexibility will accommodate new needs and constraints.
For technical reasons, also, Python's "object-oriented" syntax has proven to be excellent for teamwork. Experience has shown that engineers working in different areas, and even the same programmers returning to old programs, read unfamiliar Python source code comfortably. This is Python's greatest strength in my own work. As a highly-expressive, object-oriented, well-structured, interoperable language, it promotes the success of large complex projects in a way no other language does.
One-liners, education, serious mission-critical applications: these still don't span Python's capabilities. The language also has unique benefits to developers of graphical user interfaces (GUIs).
GUI tools used by C, C++, and Java programmers have given GUI development a reputation for being inherently difficult and tedious. Python makes things easier and you more productive. A complete minimal GUI script can be as small and readable as:
from Tkinter import * Label(text="Alert! Your first Python GUI application works!").pack() mainloop()
Python's scalability extends to GUI development too. It stretches all the way from tiny programs like this to the largest GUI applications. Python's "interoperability" -- how it plays with others -- helps here, too. Python can connect to the graphic toolkits used by C, C++, and Java programmers. Python makes even the most difficult and tedious of these toolkits considerably more tractable.
This flexibility occasionally overwhelms newcomers to the Python language. Java programmers, for example, learn a single set of tools as the one true way to build GUIs with Java. Python, in contrast, offers at least a dozen different toolkits for its projects. Still, there's a clear standard for general-purpose work: the base Python distribution includes the Tkinter graphical extension which works under MacOS, Unix, and Windows.
The conclusion: there's little good reason in the year 2000 for application developers to struggle with C or C++ when writing GUIs. Python affords productivity that's up to an order of magnitude greater.
A final surprise for many Python beginners is its potency for Microsoft Windows programming. Scripting languages like Python are sometimes regarded as "only for Unix" or "restricted to Web applications." In fact it was a Macintosh which hosted the first implementations of Python. Even apart from that historical footnote, portability has always been paramount in the evolution of the language. For several years now, the plurality of Python downloads from the Python home page have been for Windows.
It's not just that Python can run under Windows; it runs well there. Python is an excellent language for COM automation, on both the server and client side. COM (Common Object Model) is a Microsoft technology that means Python can efficiently handle such tasks as "Open a sequence of files as Excel spreadsheets, update certain cells, and print the resulting reports" or "Build a Word macro that uses a Python calculation to prepare a summary document."
Python Programming on Win32
As mentioned just above for GUI toolkits, Python is in many ways a better language for Windows application programming interfaces (APIs) than the Visual C++ and Visual Basic sold by Microsoft. This is possible because the crack programmers who maintain Python for Windows have simplified and corrected the rather jumbled "native" APIs. Windows programmers who use Python benefit from a more expressive syntax and more consistent exception-handling, for example.
Python has become so important in the Windows world that Microsoft Developer Network (MSDN) articles frequently cite it as an example of a language which can be used with such Microsoft technologies as dynamic HTML (DHTML), the Windows Scripting Host (WSH), and Active Server Pages (ASP).
There's not much of a catch. It's just as promised at the beginning of this article: Python has so much going for it that you could well make it the one language in which you do all your work. Even so, it's available at no charge, its downloads are much smaller than those for Java, and its licensing is quite liberal. While there are only a fraction of the books in print for Python as for Java or C++, the Python collection is of high quality. One new book, for instance, is O'Reilly's Python Programming on Win32, whose lead author is the same Mark Hammond who originally programmed so many of Python's Windows features.
Do you want support or training for Python? Several companies in the USA and around the world specialize in Python support and training. Moreover, one of the singular attractions of Python is the help freely given on mailing lists and through the comp.lang.python Usenet newsgroup. Many programmers have told me what first convinced them to try the language were these extraordinary and rewarding resources.
Most reassuring of all, you don't have to take my word for it. Download a Python processor and documentation set, dive into one of the online tutorials, and, in less than an hour from now, you'll know for yourself how programming in Python feels.
Cameron Laird is the vice president of Phaseit, Inc. and frequently writes for the O'Reilly Network and other publications.
Adding Data Visualization to Python for Producing Graphs
Discuss this article in the O'Reilly Network Python Forum.
Return to the Python DevCenter.
Copyright © 2009 O'Reilly Media, Inc.