Chapter 1. Welcome to Python!
Our introductory chapter provides some background on what Python is, where it came from, and what some of its "bullet points" are. Once we have stimulated your interest and
|
1.1. What Is Python?
Python is an elegant and robust programming language that delivers both the power and general applicability of traditional compiled languages with the ease of use (and then some) of simpler scripting and interpreted languages. It allows you to get the job done, and then read what you wrote later. You will be amazed at how quickly you will pick up the language as well as what kind of things you can do with Python, not to mention the things that have
already
been done. Your
|
1.2. Origins
Work on Python
At the time, van Rossum was a researcher with considerable language design experience with the interpreted language ABC, also developed at CWI, but he was unsatisfied with its ability to be developed into something more. Having used and partially developed a higher-level language like ABC, falling back to C was not an attractive possibility. Some of the tools he envisioned were for performing general system administration
|
1.3. Features
Although it has been around for well over fifteen years, some feel that Python is still relatively new to the general software development industry. We should, however, use caution with our use of the word "relatively," as a few
When people ask, "What is Python?" it is difficult to say any one thing. The tendency is to want to blurt out all the things that you feel Python is in one
1.3.1. High LevelIt seems that with every generation of languages, we move to a higher level. Assembly was a godsend for those who struggled with machine code, then came FORTRAN, C, and Pascal, which took computing to another plane and created the software development industry. Through C came more modern compiled languages, C++ and Java. And further still we climb, with powerful, system-accessible, interpreted scripting languages like Tcl, Perl, and Python.
Each of these languages has higher-level data structures that reduce the "framework" development time that was once required. Useful types like Python's lists (resizeable arrays) and dictionaries (hash tables) are built into the language. Providing these crucial building blocks in the
Because there is no one standard library for heterogeneous arrays (lists in Python) and hash tables (Python dictionaries or "dicts" for short) in C, they are often reimplemented and
1.3.2. Object Oriented
Object-oriented programming (OOP) adds another dimension to structured and procedural languages where data and logic are discrete elements of programming. OOP allows for associating specific behaviors, characteristics, and/or capabilities with the data that they execute on or are representative of. Python is an object-oriented (OO) language, all the way down to its core. However, Python is not
just
an OO language like Java or Ruby. It is actually a pleasant mix of multiple programming
1.3.3. Scalable
Python is often compared to batch or Unix shell scripting languages. Simple shell scripts handle simple
The
1.3.4. Extensible
As the amount of Python code
The most critical portions of code, perhaps those hotspots that always show up in the profiler or areas where performance is
This type of extensibility in a language provides
Python extensions can be written in C and C++ for the standard implementation of Python in C (also known as CPython). The Java language implementation of Python is called Jython, so extensions would be written using Java. Finally, there is IronPython, the C# implementation for the .NET or Mono platforms. You can extend IronPython in C# or Visual Basic.NET. 1.3.5. Portable
Python can be found on a wide variety of systems, contributing to its
1.3.6. Easy to Learn
Python has relatively few keywords, simple structure, and a clearly defined syntax. This allows the student to pick up the language in a relatively short period of time. What may perhaps be new to
1.3.7. Easy to Read
Conspicuously absent from the Python syntax are the usual mandatory symbols found in other languages for accessing
1.3.8. Easy to Maintain
Maintaining source code is part of the software development lifecycle. Your software usually continues to
1.3.9. Robust
Nothing is more powerful than allowing a programmer to recognize error conditions and provide a software handler when such errors occur. Python provides "safe and sane" exits on errors, allowing the programmer to be in the driver's seat. When your Python crashes due to errors, the interpreter dumps out a "stack trace" full of useful information such as why your program crashed and where in the code (file
These exception handlers can take steps such as defusing the problem, redirecting program flow, perform cleanup or maintenance measures, shutting down the application gracefully, or just ignoring it. In any case, the debugging part of the development cycle is reduced considerably. Python's robustness is beneficial for both the software designer and the
1.3.10. Effective as a Rapid Prototyping Tool
We've mentioned before how Python is easy to learn and easy to read. But, you say, so is a language like BASIC. What more can Python do? Unlike self-contained and less flexible languages, Python has so many different interfaces to other systems that it is powerful enough in features and robust enough that entire systems can be prototyped completely in Python. Obviously, the same systems can be completed in traditional compiled languages, but Python's simplicity of engineering allows us to do the same thing and still be home in time for supper. Also,
1.3.11. A Memory Manager
The biggest pitfall with programming in C or C++ is that the responsibility of memory management is in the hands of the developer. Even if the application has very little to do with memory access, memory modification, and memory management, the programmer must still perform those
Because memory management is performed by the Python interpreter, the application developer is able to steer clear of memory issues and focus on the immediate goal of just creating the application that was planned in the first place. This leads to fewer
1.3.12. Interpreted and (Byte-) Compiled
Python is
Core Note: File extensions
|