Ziff-Davis Enterprise 
DevSource: Microsoft Developer Resource
Add OnsArchitectureLanguagesTechniquesUsing VSForums
 
Home arrow Languages arrow (More Than) Five Things You Didn't Know You Could Do With Python
(More Than) Five Things You Didn't Know You Could Do With Python
By Cameron Laird

Rate This Article:
Add This Article To:
(More Than) Five Things You Didn't Know You Could Do With Python
( Page 1 of 5 )

Think Python's just a scripting language? Cameron Laird explains how you can use it for COM, .NET, or Java development... and that's just the start.

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.

ADVERTISEMENT

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:

  • 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.



 
 
>>> More Languages Articles          >>> More By Cameron Laird
 



DevSource video
Devsource Video Series
Manipulating Society through Technology
Jeremy Bailenson, Director of the Virtual Human Interaction Lab at Stanford University, talks about virtual reality, avatars, Moore's law, how real world behaviors influence online reality, and societal manipulation through technology!
>> Play video
>> Read article
>> See all videos
DevLife Blog

Julia explores the Robotics Studio! (It's for more than you think.)

MSDev Blog

Messages for Bill Gates!

Make it Work
.NET makes runtime type checking a breeze. See what Peter has to say about it in this week's tips!
News
Microsoft Counts on App Support for Vista
Microsoft has taken pains to demonstrate that Windows Vista will have ample application support.
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.