Can use Python

1. To give you a taste¶

Anyone who works a lot on the computer comes to the conclusion that there are tasks that they would like to automate. For example, a search-and-replace for a variety of files, or the ability to rename or rearrange a bunch of photo files in a complicated way. Or maybe you'd like a small custom database, a specialized GUI application, or a simple game.

As a professional software developer one may have to work with several C / C ++ / Java libraries, but find the usual writing / compiling / testing / recompiling cycle too slow. Those who write a test suite for such a library may find it a tedious task to write the test code. Perhaps one or the other has also written a program that could use an extension language, but does not want to design and implement a completely new language for his program.

Then Python is exactly the right language!

You could of course write Unix shell scripts or Windows batch files for some of these tasks. Shell scripts are good for moving files and changing text data, but they are less suitable for developing GUI applications or games. You could write a corresponding C / C ++ / Java program for it, but it usually takes a lot of development time to even develop a first draft program. Python is easier to use, available for Windows, Mac OS X, and Unix operating systems, and helps get the job done faster.

Python is easy to use, but a real programming language that provides much more structure and support for large programs than shell scripts or batch files could. On the other hand, Python also offers more error checking than C and, as a highly abstract high-level language, has built in more abstract data types such as flexible arrays and dictionaries. Because of its more general data types, Python can be used in broader problem areas than Awk or even Perl, and yet many things in Python are at least as simple as they are in these languages.

Python allows programs to be broken down into modules that can be reused in other Python programs. It comes with a large collection of standard modules that can be used as the basis for your own programs; or as examples to learn programming in Python. Some of the modules provide file I / O, system calls, sockets and even interfaces to GUI toolkits like Tk.

Python is an interpreted language, which saves a considerable amount of time in program development, since compiling and linking are not necessary. The interpreter can be used interactively so that one can easily experiment with the capabilities of the language, write disposable code, or test functions during bottom-up program development. It's also a handy desktop calculator.

Python enables the development of compact and readable programs. Programs written in Python are much shorter than C / C ++ / Java equivalents for several reasons:

  • The abstract data types allow complex operations to be expressed in a single statement;
  • Statements are grouped by indentation rather than opening and closing brackets;
  • Variable or argument declarations are not necessary.

Python is expandable: Anyone who can program in C can simply add a new built-in function or module to the interpreter. Either to execute time-critical operations at maximum speed or to link Python programs to libraries that are only available in binary form (such as manufacturer-specific graphics libraries). Once you are familiar with Python, you can link the Python interpreter to applications written in C and use Python as an extension or command language for this application.

By the way: The language is named after the BBC program “Monty Python’s Flying Circus” and has nothing to do with reptiles. Using allusions to Monty Python skits in documentation is not only allowed, but welcomed.

Now that you're really hot for Python, you'll want to know and learn more. The best way to learn a language is definitely to use it. That is why the tutorial invites you to experiment with the Python interpreter while reading.

The next chapter explains the technical part of using the interpreter. This is rather sober information, but important in order to be able to try out the examples shown later.

The rest of the tutorial uses examples to introduce different possibilities and language elements of Python. This starts with simple expressions, statements and data types and continues with functions and modules. It then covers advanced concepts such as exceptions and custom classes.