Interacting with the IronPython Environment

Must Read

How to make money marketing your business on facebook

By now, it is common knowledge that for virtually any business, Facebook matters. Mark Zuckerberg was recently named Time...

Tips For Having a Safe Summer

Summer is one of the best times of the year. The weather is great, people can get outside, and...

Private Student Loan Or Federal Student Loan – The Choice is Yours

Federal Student LoansLoans granted are based on the credit score of the borrower. The interest rates are fixed and...

At this point, you know how to create basic functions; determine which modules, objects, and functions are available for use; and import external modules as needed. The last major basic task you need to know about is interacting with the IronPython environment. Knowing this information will help you create better applications. The following sections provide an overview of many environmental needs you’ll have when using IronPython.

Obtaining Version Information

You may find a need to programmatically process the version information for a particular IronPython installation. Perhaps your application requires a newer version of IronPython. You can obtain this information programmatically using the sys.version attribute. The following  code shows a simple method for checking the IronPython version.

import sys
print sys.version

Of course, your concern may revolve around Windows. In this case, you can use sys.getwindowsversion() to obtain the information you need. The output is an array containing the following five values:

  • Major version
  • Minor version
  • Build
  • Platform
  • String describing installation (such as the current service pack)

Changing sys.path Values

The sys.path attribute is an array containing paths to various parts of IronPython. You can use sys.path to locate or modify the path for IronPython. For example, if you type print sys .path[0] and press Enter, you obtain the path for the currently executing application. The standard list provides these locations:

  • Executing application path (blank if the interpreter can’t determine the location)
  • IronPython library directory
  • IronPython DLL directory
  • IronPython executable directory
  • IronPython site-packages directory

The interpreter always searches these paths, looking for any modules you want to import or other resources your application requires. You can add or remove entries as necessary.

Obtaining Command Line Arguments

An application can receive command line arguments when it executes and then processes those arguments, just as you would do with any other application. IronPython uses a similar approach to that of C and C++. You use the sys.argv array to obtain a list of the arguments passed at the command line. For example, if you type print sys.argv[0], you see the first command line argument passed to the application. The sys.argv array is blank when you start the interpreter without specifying a module to execute.

If you’re getting the idea that loading the sys module provides all kinds of power for your application, you’re right. You can see a complete list of the sys module functions and attributes at Of course, you’ll see additional examples as the book progresses.



Please enter your comment!
Please enter your name here

Latest News

Underlight As Accent, For Power and The Main Light for Photography

Underlighting, in which fill or accent light comes from under the topic, is not widely used technique in the traditional Portraits,...

How To Fix Overexposure As A Creative Tool, The Complete Guide

As an creative tool, overexposure is sort of underrated. What I’m close to propose could be a deliberate and well thought out technique for...

7D Mark II is Canon’s best DSLR cameras without full-frame sensor.

The expected long-awaited Canon EOS 7D Mark II are shipping in November for $ 1,799 without a lens. With a higher price tag, you...

Low key photography and How to isolate your subject.

Low key photography doesn’t depend on underexposure to make its point; the key to low key is that the majority of tones, even correctly...

High Key Lighting Techniques for Professional Photographers

I’ve written many times about high key lighting techniques and how to achieve them. The term “high key” is a bit misleading. As I’ve...

More Articles Like This

blograby facebook like page