Blograby

Considering the Standard Library Feature

 

The Python Standard Library is the centerpiece of any IronPython you want to create of any complexity. If you want to ensure that your IronPython application will run on other platforms using other Python interpreters, then you need to stick with the functionality that the Standard Library provides and avoid the temptation to use .NET features in your application. Of course, the first thing you’ll want to do is discover what the Standard Library can do for you — perhaps it contains everything you need and falling back on .NET won’t be a problem.

Interestingly enough, IronPython does ship with a version of the Standard Library that’s been tuned for maximum compatibility with IronPython. Of course, the problem word in that previous sentence is “tuned.” If you want to ensure maximum compatibility outside the IronPython environment, you must download a copy of the Python Standard Library, install it on your machine, and use it in place of the IronPython equivalent. It’s also important to know that the IronPython version of the Standard Library isn’t complete. You won’t have all the functionality that other Python developers have unless you use the Python Standard Library.

Whichever version of the Standard Library you use, you’ll need to import modules into your application before you can use them. This chapter provides a few tricks and techniques you can use to make accessing the modules easier. It’ll also explain how IronPython locates the modules so you don’t spend a lot of time trying to figure out why a particular module is seemingly inaccessible.

Considering the Standard Library Features

The Standard Library comes with a number of features not found in IronPython. Of course, there are all those missing modules. If you look in Python26Lib you’ll find that the Python Standard Library contains 256 modules in the main library directory, while IronPython has only 186. (Table 6-1 shows a complete list of the missing modules — each module contains a header telling you about the task it performs.) In addition, the Python library contains 20 subdirectories, while IronPython has only 11. In short, the IronPython version of the Standard Library has a lot to offer; the Python version of the Standard Library has more. Here’s a list of the missing directories:

Table 6-1: Standard Library Modules Missing from IronPython

Getting all of the modules found in the original Python Standard Library would be reason enough to download, install, and use it. However, the Python Standard Library provides a number of additional features in the form of help files and utilities. Although you can’t use the utilities to perform .NET-specific work, you can use them to ensure your code is truly compatible with Python, which is a big deal if you plan to use your application on other platforms. With this in mind, here’s a list of the additional help files and utilities provided with the Python Standard Library.

Now that you have a better idea of what the Python Standard Library provides, you need to consider how you’ll use it or whether you want to use it at all. Just how the Python Standard Library affects your organization and you depends on your goals. For the most part, you’ll use these tools when you want to write pure Python applications or applications that rely heavily on Python (versus the mixed language applications found later in this book). It’s important to remember that IronPython has a lot to offer that Python doesn’t, so you need to decide which route your organization will take before you make a commitment to pure Python by using the Python Standard Library.


 

Exit mobile version