An_Introduction_To_Python_Programming_2005_Shuttleworth.pdf

(3385 KB) Pobierz
An Introduction to Python Programming
James Shuttleworth and Sarah Mount
2005
Preface
Why learn to program?
Why bother to learn a programming language when you can already use a computer just
by pointing and clicking on your desktop icons? Whenever you use a computer in the
conventional way, you are restricted by what some other programmer has allowed you to
do. If you want to
really
be in control of your computer, you need to be able write your
own code. Not only will you be able to develop applications from scratch, more and more
software packages allow you to extend their capabilities by writing plugins. The ray tracer
PovRay and the GIMP raster graphics package are examples of extensible applications.
Programming is also an essential skill in the computing industry. Pretty much any job
you can think of involves at least some programming. Learning the fundamental concepts
of programming languages and systems, as well as the facilities of one or more languages
will put you ahead of the game in terms of employability. It’s also worth considering that
programming languages tend to rise and fall in popularity. Python is on the way up, but at
some point it’ll be overtaken by the Next Big Thing
. In these notes we’ll be teaching you
as much about programming in general as Python specically. At the end of the module,
you will also go on to study other languages, such as Java. These experiences will give you
the exibility to learn new languages whenever they become popular, which will keep you
in a job much longer than those people who will learn a single language (COBOL?!) and
have diculty retraining in years to come.
This introduction to programming was written specically for students who have no
prior experience of writing software. We’ve tried to teach everything from scratch and
make it fun and interesting along the way. Last year we saw some fantastic results (and
great code) from students, almost all of whom had never written a program before. The
External Examiner said about our approach:
The institution’s approach to the teaching of programming is novel and is
very successful: it gives Coventry University students a head start compared
to approaches commonly used elsewhere in the UK.
iii
iv
Why Python?
In 2005 we decided to start using Python for introductory programming modules at Coven-
try. We are not the only University to make this switch – Leeds University and the Uni-
versity of Oregon are among those beginning to use Python. However, many Universities
use other languages and we thought it might be helpful to explain why we believe that
Python is such a great choice.
Python is easy to learn
The syntax of Python is based on a language called ABC which was specically developed
to be easy to learn and understand. As Python has developed to become an industrial
strength language, its creator, Guido van Rossum, has gone to some lengths to make sure
that the language remains as easy to use as possible. Programmers often describe the
way Python code looks as “clean” and “simple”. So, we think you’ll be able to pick it up
quicker than other languages and be able to write quite sophisticated programs early on
in your studies.
When Python was rst born, it was always hoped that it would become a language
widely used in education. For that reason, Python has a lot of built-in support for learners
– especially the turtle graphics module that you will meet in Chapter 1 of this book and
use in your rst Studio.
Python is used in dierent sorts of applications
Like XML, scripting was extremely useful as both a mod tool and an internal
development tool. If you don’t have any need to expose code and algorithms in a
simple and safe way to others, you can argue that providing a scripting language
is not worth the eort. However, if you do have that need, as we did, scripting
is a no brainer, and it makes complete sense to use a powerful, documented,
cross-platform standard such as Python.
Python, like many good technologies, soon spreads virally throughout your
development team and nds its way into all sorts of applications and tools. In
other words, Python begins to feel like a big hammer and coding tasks look like
nails.
– Mustafa Thamer of Firaxis Games, talking about Civilization IV. Quoted
on page 18 of the August 2005 Game Developer Magazine
http://www.gdmag.com/
Python is capable of implementing pretty much any sort of program you might wish to
write. It is used in web application, scientic programming, business applications, image
processing, games, database programming and probably anything else you can think of.
The number of useful things you can do quickly with Python seems to be expanding all
the time, as more and more people and companies are using the language.
v
Python has fantastic library support and an active
user community
I have the students learn Python in our undergraduate and graduate Seman-
tic Web courses. Why? Because basically there’s nothing else with the exibility
and as many web libraries.
– Prof. James A. Hendler, University of Maryland
Python has fantastic online support, in the form of documentation, tutorials and even
books. Many of these are listed in our “recommended reading” in Section and many of
them are free. So, you will be well supported in your learning, both inside the University
and outside.
Python is increasingly used in industry
Python has been an important part of Google since the beginning, and re-
mains so as the system grows and evolves. Today dozens of Google engineers
use Python, and we’re looking for more people with skills in this language.
– Peter Norvig, director of search quality at Google, Inc.
NASA is using Python to implement a CAD/CAE/PDM repository and
model management, integration, and transformation system which will be the
core infrastructure for its next generation collaborative engineering environ-
ment. We chose Python because it provides maximum productivity, code that’s
clear and easy to maintain, strong and extensive (and growing!) libraries, and
excellent capabilities for integration with other applications on any platform.
All of these characteristics are essential for building ecient, exible, scalable,
and well-integrated systems, which is exactly what we need. Python has met or
exceeded every requirement we’ve had.
– Steve Waterbury, Software Group Leader, NASA STEP Testbed.
Whilst we want you to become competent and well-educated programmers, we realise
that at some point many of you will earn a living in the Computer industry. Almost any
job you might nd will require some programming skills. System administration, system
analysis, programming(!), online content creation and games development all require pro-
gramming skills of some sort. Animation also often requires some scripting and many
graphics and animation packages now come with scripting capabilities built-in. Knowledge
of Python should serve you well whatever you choose to do later on.
Python runs on many platforms
Python can run on PCs, Macs on Windows operating systems, or Linux, or Mac, or pretty
much anything else. Recently, Nokia released a Python SDK
1
with which you can write
Python programs for mobile phones running the Symbian OS.
1
http://www.forum.nokia.com/main/0,,034-821,00.html
Zgłoś jeśli naruszono regulamin