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 argu-
ment passed to the application. The
sys.argv
array is blank when you start the interpreter without
specifying a module to execute. You’ll see command line processing examples as the book progresses
because this is a powerful feature.
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
http://docs.python.org/library/sys.html
. Of
course, you’ll see additional examples as the book progresses.
USINg IRoNPyTHoN CoNSTRUCTIVEly
This is a chapter of basics. It’s the training-wheels chapter of the book because everyone needs to
start somewhere. However, this chapter didn’t start at the ground floor — I assumed you already
know something about programming in general and .NET languages in particular, so this chapter
548592c02.indd 41
2/24/10 12:47:24 PM
www.finebook.ir
42
❘
CHAPTER 2
Understanding the ironPython Basics
didn’t have a lot of handholding in it. Consequently, you learned quite a bit about IronPython,
including how to indent and use capitalization, work with data types, use modules, create functions,
and control the environment. You’ll probably use the information in this chapter so much that you
won’t need the chapter after a while, but in the meantime keep a bookmark on it so you can refer to
it as you progress through the other introductory chapters.
It’s time to get a little work done with your IronPython setup. The first step is to get used to working
with Visual Studio and IronPython. You won’t find any fancy templates to do the work for you, so
make sure you practice creating some projects. In addition, put some simple projects together using the
techniques described in this chapter. The projects don’t have to do anything fancy; all you’re trying to
do is get the procedure for creating and managing projects down. Try creating a few applications that
use functions and exercise the various data types. Have a little fun with the
print()
function!
Chapter 3 builds on what you learned in this chapter. The next step is to work with some structured
programming elements such as loops. The pace really is going to pick up, so make sure you spend
the time required in each chapter to build your knowledge — otherwise, you’re going to get lost
pretty quickly. Even so, Chapter 3 is still a basics chapter (as are Chapters 4 and 5).
548592c02.indd 42
2/24/10 12:47:24 PM
www.finebook.ir
Do'stlaringiz bilan baham: |