Using The Ironpython Console

The IronPython console is the best place to begin working with IronPython. You can enter a few statements, test them out, and then work out additional details without too many consequences. In addition, because the console is interactive, you obtain immediate feedback, so you don't have to wait for a compile cycle to discover that something you're doing is completely wrong. In fact, even after you've mastered IronPython, you'll find that you use the console to try things out. Because IronPython is a dynamic language, you can try things without worrying about damaging an application. You can test things quickly using the console and then include them in your application. The following sections describe the IronPython console and how to use it. Expect to see the IronPython console in future chapters.

Opening and Using the Default Console

The IronPython console is an application provided with the default installation. You access it using the Start O Programs O IronPython 2.6 O IronPython Console command. The console, shown in Figure 1-3, looks something like a command prompt, but it isn't.

Ironpython Tutorial
FIGURE 1-3: The IronPython console looks something like a command prompt.

Notice that the top of the window tells you which version of IronPython you're using and which version of the .NET Framework it's running on. This is important information because it helps you understand the IronPython environment and what limitations you have when working with IronPython. Below this first line, you'll see some commands that Microsoft thought you might find useful. The "Getting Help with Any Function" section of the chapter tells you more about the Help command.

To use the console, simply type the commands you want to issue. When you're done, IronPython will execute the commands and output any result you requested. A command need not be a function call or an object instantiation as it is in other languages. For example, type 2 + 2 right now and then press Enter. You'll see the result of this simple command, as shown in Figure 1-4.

FIGURE 1-4: IronPython is dynamic and the console is interactive.

Whenever you want to end a particular task, such as working with Help, press Enter a second time. The console will take you to the previous level of interaction.

Getting Help with Any Function

You can get help with any function in the console. If you simply type help and press Enter in the console, IronPython tells you how to request interactive help or help about a specific object. To begin interactive help, type help() and press Enter. You'll see the interactive help display shown in Figure 1-5.

IronPython Console

IronPython ?.. f> <2.6.i0928.8> on .NET 2.8 .SB727.2%$?.

"ype "help", "copyright", "credits" or "license" for more information. »> help "

Type helpO for interactive help, or help(object> for help about object, »> helpO

Welcome to Python This is the online help utility.

If this is your first tine using Python, you should definitely check out the tutorial on the Internet at http:/Vdocs .python .org^tutorial/.

iinter the nane of any, keyword., or tpjiic to get help on inviting Python programs and using Python nodules. To quit this help utility and return to the interpreter, just type "quit".

To get a list of available nodules, keywords, or topics, typ? "nodules", keywords", or "topics". Each nodule also cones with a one-line sunnary of what Lt does; to list the nodules whose summaries contain a given word such as "span", type "nodules span".


FIGURE 1-5: Interactive help lets you ask questions about IronPython.

Let's say you have no idea of what you want to find. Console help provides you with a list of words you can type to get general help. These terms are:




Type any of these terms and press Enter. You'll see a list of additional words you can type, as shown in Figure 1-6 for modules. Using this technique, you can drill down into help and locate anything you want. In fact, it's a good idea to spend some time in help just to see what's available. Even advanced developers can benefit from this approach — I personally follow this approach when I have time to increase my level of knowledge about all of the languages I use.

IronPython will constantly refer you to the online help for Python. So you might as well check it out now. You'll find a good Python tutorial at While you're at it, there's also a good IronPython-specific tutorial that comes with your installation. Simply choose Start O Programs O IronPython 2.6 O IronPython Tutorial. Although these sources of help are useful, you'll get a much better start working through the examples in the book.

You might know about the topic you want to find. For example, you might know that you want to print something to screen, but you don't quite know how to use print. In this case, type help('print') and press Enter. Figure 1-7 shows the results. You see complete documentation about the print keyword.

Understanding the IPY.EXE Command Line Syntax

When you open a console window, what you're actually doing is executing IPY.EXE, which is the IronPython interpreter. You don't have to open a console window to use IPY.EXE. In fact, you normally won't. It's possible to execute IronPython applications directly at the command line. The following sections discuss IPY.EXE in more detail.

Adding IPY.EXE to the Windows Environment

Before you can use IPY.EXE effectively, you need to add it to the Windows path statement. The following steps provide a brief procedure.

1. Open the Advanced tab of the Computer (or My Computer) applet.

2. Click Environment Variables. You'll see an Environment Variables dialog box.

3. Highlight Path in the System Variables list. Click Edit. You'll see the Edit Environment Variable dialog box.

IronPython Console

uhile I «father a

list of all available



keyuo rd










s b<s



site lue









s ite












soc ket

cookie lib

Was this article helpful?

0 0


  • fikru
    What is ironPython console?
    5 months ago

Post a comment