Feeds

Quick scripting for .NET with IronPython

Office benefits

Combat fraud and increase customer satisfaction

Hands on, part 1 While Ruby and Groovy seem to get all of the attention, there's one scripting language that has been around for a lot longer and that has quietly been picking up in popularity over the long run. That language is Python, and, according to the TIOBE Programming Community Index Python was the language of the year for 2007.

While development of the core version of Python (often called CPython - because it's coded in C) continues apace, there are also versions that target the two big software platforms: Jython targets the Java platform (using the Java Virtual Machine and inter operating with native Java code), and the other is IronPython, which targets Microsoft's .NET Framework and was discussed at Microsoft's Mix 08 conference last week.

The current version of IronPython (version 1.1.1, released at the end of January 2007), uses the .NET Common Language Runtime, while the next major release will be built on top of the Dynamic Language Runtime, which runs on top of the CLR. In this two parter we'll take a look at IronPython and the IronPythonStudio, which is built on Visual Studio 2008, officially launched last month, starting with a look at the language itself.

The simplest way of getting IronPython is to download the latest release from CodePlex. Installation is as simple as downloading and unpacking the zip. Once done, navigate to the appropriate directory and simply enter ipy to start the interactive Python interpreter:


C:\IronPython-1.1.1>ipy
IronPython 1.1.1 (1.1.1) on .NET 2.0.50727.1433
Copyright (c) Microsoft Corporation. All rights reserved.
>>> print 'hello world'
hello world

Now, old Python hands will be wondering about the availability of some of the standard Python modules that they know and love. IronPython doesn't include all of these by default, so the first thing to do in that case is to point it at that library. To do this, just append a pointer to the standard library to the sys.path. At the ipy prompt just enter the following:


>>>import sys
>>>sys.path.append(r'c:\Python25\lib')

As a test let's grab hold of an old (and very, very useful) module called glob (which is used for Unix-style file/path name expansions) that isn't included in IronPython. Now that we have the sys.path set, it's just a case of doing the import - we'll do that and use it to grab a list of msi files in the c:\download directory:


>>>import glob
>>>glob.glob(r'c:\download\*.msi')
['c:\\download\\IronPythonStudio.msi', 'c:\\download\\python-2.5.1.msi']

So far so good, we can use Python like we used to. But the real meat of IronPython is access to the .NET Framework and all that it contains. To illustrate this we're going to write some code that mixes and matches .NET libraries with CPython modules, and that is going to involve grabbing hold of Excel as well. This application will take a path name and list some details of all of the Excel workbooks that it can find. Now, to do this requires that we have the Primary Interop Assemblies for Microsoft Office in place. These are included by default with Office 2007, but need to be installed separately for Office 2003 - full details are included here.

Combat fraud and increase customer satisfaction

More from The Register

next story
This time it's 'Personal': new Office 365 sub covers just two devices
Redmond also brings Office into Google's back yard
Oh no, Joe: WinPhone users already griping over 8.1 mega-update
Hang on. Which bit of Developer Preview don't you understand?
Microsoft lobs pre-release Windows Phone 8.1 at devs who dare
App makers can load it before anyone else, but if they do they're stuck with it
Half of Twitter's 'active users' are SILENT STALKERS
Nearly 50% have NEVER tweeted a word
Internet-of-stuff startup dumps NoSQL for ... SQL?
NoSQL taste great at first but lacks proper nutrients, says startup cloud whiz
Next Windows obsolescence panic is 450 days from … NOW!
The clock is ticking louder for Windows Server 2003 R2 users
Ditch the sync, paddle in the Streem: Upstart offers syncless sharing
Upload, delete and carry on sharing afterwards?
Microsoft TIER SMEAR changes app prices whether devs ask or not
Some go up, some go down, Redmond goes silent
Batten down the hatches, Ubuntu 14.04 LTS due in TWO DAYS
Admins dab straining server brows in advance of Trusty Tahr's long-term support landing
prev story

Whitepapers

SANS - Survey on application security programs
In this whitepaper learn about the state of application security programs and practices of 488 surveyed respondents, and discover how mature and effective these programs are.
Combat fraud and increase customer satisfaction
Based on their experience using HP ArcSight Enterprise Security Manager for IT security operations, Finansbank moved to HP ArcSight ESM for fraud management.
The benefits of software based PBX
Why you should break free from your proprietary PBX and how to leverage your existing server hardware.
Top three mobile application threats
Learn about three of the top mobile application security threats facing businesses today and recommendations on how to mitigate the risk.
3 Big data security analytics techniques
Applying these Big Data security analytics techniques can help you make your business safer by detecting attacks early, before significant damage is done.