Python Overview
Python is the single computing language with the widest span: it effectively tackles more problems than even C or Java, which most programmers regard as the standards for versatility in software.
That's what I've asserted, at least, in articles and courses for seven years. While a minority of my own coding involves Python, for various business reasons, I've only grown more certain of the conclusion during that interval.
Even if your enthusiasm for the language doesn't match mine, though, you owe it to yourself to know the most important tasks Python can take on in a typical Windows programming environment.
Most magazines and books do not mention:
Most magazines and books do not mention:
Python does COM; Python does .NET; Python does Java better than Java; Python is high-performance; and Python talks to hardware. Python Protects E-mail Everyone knows that VC++ and VB are the ways to program COM work. Not me, though; it's been several years since I've used either for that purpose. Python gives me full ability to construct both COM clients and servers. The language does this not only more compactly and elegantly than either VC++ or VB, but with full interactivity: I can experiment at a Python interactive prompt. This is particularly valuable during COM work, because the COM servers I interface are often only partially documented.
Even with the most widely-known examples of COM, though, Python is a winner. Python inventor Guido van Rossum points out that "SpamBayes [is] a very successful personal spam fiter which integrates with Outlook via COM." SpamBayes is open-sourced, like many Python projects, so you can view the source and see for yourself how it works. Note, though, that you are equally free to use Python for proprietary products.
If you do look in the SpamBayes source, you'll see that the message-store manager of the Outlook 2000 part of the project, for example, embeds this self-testing definition which prints an inbox's contents to the standard output stream:
def test(): from win32com.client import Dispatch outlook = Dispatch("Outlook.Application") inbox = outlook.Session.GetDefaultFolder(constants.olFolderInbox) folder_id = inbox.Parent.StoreID, inbox.EntryID store = MAPIMsgStore() for folder in store.GetFolderGenerator([folder_id,], True): print folder for msg in folder.GetMessageGenerator(): print msg store.Close()
Judge for yourself how readable this is compared to its C++ or VB equivalents.
COM isn't an isolated strength of Python on Windows, incidentally. One of the first books focused on the language was Python: Programming on Win32, and the language is a good vehicle not just for such older technologies as DDE and MFC, but also still-growing .NET. Python Does .NET (Almost).
In principle, the same is true with .NET as with COM. Microsoft worked closely with Python insiders when it was first designing .NET, and "Project 7" planned Python as a fully-capable .NET language since 1998.
In principle, the same is true with .NET as with COM. Microsoft worked closely with Python insiders when it was first designing .NET, and "Project 7" planned Python as a fully-capable .NET language since 1998.
Those .NET capabilities aren't as convenient as the corresponding COM ones, but it's widely expected they'll become more so later this week. As things stand now, to write a .NET client requires use of a Python "extension" called PythonNet. While PythonNet is a freely-available add-on, it's generally not part of a standard installation. Once you've downloaded and installed it, though, you can work with any .Net Classes. Here's an example with Drawing:
from CLR.System.Drawing import Point p = Point(10, 5)
In this fragment, p is now a first-class binding in Python; it can be referred, passed, interrogated, and so on, just like any other Python value. At the same time, it's a .NET Point. In fact, Python even lets you subclass .NET definitions, as well as invoke methods, manage events, call indexers, instantiate delegates (including multicasts), dereference arrays, and iterate collections. Python gives almost complete access to .NET facilities; the most prominent exceptions are that Python doesn't respect CLR security, and Python semantics don't provide for value types. The practical consequence of the latter is that some operations that C# can write as assignments, Python must do in two steps, as copies.
There's no effective way to write .NET services with Python now. However, this is the week of PyCon2005, the biggest of several annual conferences focussed on Python. The first keynoter on the first morning of PyCon2005 is scheduled to be Jim Hugunin, a researcher for Microsoft Corporation. Gossip has it that he'll announce an enhanced release of IronPython, a project designed exactly to make Python a full-fledged .NET language.
A Better Java than Java One habit we have with customers is to say that the decision facing a particular project is not between Python and some other language, but what proportions to use of each. There are choices besides "all" and "nothing." Most of our contracts end up implemented in a mixture of languages, because that turns out to be the most cost-effective way to achieve the reliability and functionality we deliver.
Python and Java make for particularly interesting contrasts and combinations. Although Java has a reputation as the paramount "enterprise" language, our experience is that Python actually "scales" and promotes teamwork better than Java does. One effective way to exploit the strengths of each is to use Jython to script and develop applications based on Java class libraries.
0 Comments