36
❘
CHAPTER 2
Understanding the ironPython Basics
functions. In fact, you can see the entire list of built-in functions at
http://docs.python.org/
library/functions.html
.
FIgURE 2-17:
Use str() or repr() as appropriate to create output for your application.
You’ll see a wealth of data types as the book progresses. For example, Chapter 4 discusses arrays
and collections, Chapter 5 tells you all about objects, and Chapter 6 begins a discussion of working
with the standard library. There are a number of online resources for working with data types as
well. The two best sources — the ones used for this book — are at:
➤
http://www.python.org/doc/2.4.4/lib/types.html
➤
http://docs.python.org/library/datatypes.html
➤
➤
ExPloRINg THE IRoNPyTHoN ModUlES
In Chapter 1, you used the interpreter to work with IronPython. However, the moment you closed the
interpreter, everything you did was gone. Working directly with the interpreter means that your work
is temporary, which is fine when you want to experiment, but not a good idea when you want to write
longer applications or save your work for posterity. Consequently, in this chapter, you’ve used Visual
Studio to work with Python files that have a .py extension. These files are known as modules.
Just like any other programming language, you’ll find it worthwhile to place some code in separate files.
For example, you might create a math library that contains your favorite math functions. Rather than
copy those functions everywhere, you place them in a separate module and then import that module as
needed into an application. In order to make this setup work, you must know how to import modules
and use them within the application. The following sections discuss modules and how you work with
them in IronPython.
Considering built-in and External Modules
IronPython uses the concept of built-in and external modules. A built-in module is one that you can
access all the time from within the interpreter. For example, the
str()
function is part of a built-in
module. All the code that the interpreter relies upon to perform basic tasks is part of a library of
modules that comes with IronPython. In fact, you can see these modules in the
\Program Files\
IronPython 2.6\Lib
directory of your installation.
548592c02.indd 36
2/24/10 12:47:22 PM
www.finebook.ir
Do'stlaringiz bilan baham: |