Download - All IT eBooks

Transcript
CHAPTER 3
The Python Programming Language
I just want to go on the record as being completely
opposed to computer languages. Let them have their
own language and soon they’ll be off in the corner plotting with each other!
—Dr. Steven D. Majewski
A key requirement for automated instrumentation is the ability to describe what needs
to be done in terms that a computer, or some other type of automated control system,
can execute. While the term “programming” might immediately come to mind for some
readers, there are actually many ways to do this, some of which don’t even involve a
programming language (at least, not in the conventional sense). However, in this book
we will be using Python, along with a smattering of C, to create software for automated
instrumentation.
This chapter is intended to give you a basic introduction to Python. In the next chapter
I’ll introduce the C programming language, which we’ll use to create extensions for
Python that will allow you to interface with a vendor’s driver, or create modules for
handling computation-intensive chores. This chapter is not intended as an in-depth
tutorial or reference for Python; there are many other excellent books available that can
fill those roles (refer to the references at the end of this chapter for suggested reading).
There is also an extensive collection of documents available at the official Python website, ranging from beginner’s tutorials to advanced topics.
Python was chosen as the primary programming language for this book for several
reasons: it’s relatively easy to learn; it doesn’t require a compilation step, so one can
execute programs simply by loading them (or just typing them in, if you’re brave
enough); and it is powerful and full-featured. Python is also rather unique in that it
supports three different programming models—procedural, object oriented, and
functional—simultaneously. To begin, we will generally be using the procedural paradigm. Later, when we start working with graphical user interface (GUI) designs and
extensions written in C, we will encounter situations where it will be necessary to put
59