In this section we'll introduce you to Python as a starting point if you're interested in learning to program a more fully featured language. If you've been around Linux any longer than a month or two, you've probably heard of Python. So what is it?
Like Perl and Bash scripts, Python is a scripting language, and programs are usually distributed and run as text files full of commands. Unlike Bash, Python is not a pure interpreted language. With a Bash script, the Bash interpreter takes lines of the program one at a time and executes them.
With Python however, the Python interpreter reads in the source code file and translates it into an intermediate form, which is run on a virtual machine much like the Java virtual machine.
The advantage of this is that if your program contains looping constructs where the same statement is executed a number of times, the loops are only translated into the intermediate form once. This is similar to how C programs work, except that C programs are compiled to a form which runs on a specific machine type.
As well as being a great language for an experienced programmer to get things done quickly, Python is an ideal language for the first-time programmer. It has built-in support for strings, arrays (multidimensional variables) and dictionaries (which are much like miniature databases) and has a very simple and uncluttered syntax. It encourages good programming practices but at the same time is extremely flexible and powerful.
Python makes it easy to separate parts of a program into blocks and tasks which can be kept in separate files. This helps make programs more modular and in the end more maintainable. It also encourages the writing of generic libraries of functions which can be reused over and over again.
All these features allow Python to scale from small 50-line scripts to large projects with teams of programmers and tens of thousands of lines of code. Python is also an object-oriented language with a clean and elegant class system that hasn't just been bolted onto an existing procedural language.
Now that you're sold on the Python feature set, you're probably wondering what you can use it for. In addition to standard scripting tasks, Python is well suited to GUI programming, CGI scripting, networking servers and clients, text file manipulation and a host of other tasks. Python code is highly portable and it is relatively easy to write code which runs on Unix as well as other operating systems. The only places where compiled languages such as C or C++ have an advantage are in areas like kernel and library programming or in applications where speed is one of the primary objectives.
For a final piece of Python advocacy we suggest you read the experiences of an advanced hacker (Eric S Raymond) with Python: www2.linuxjournal.com/ lj-issues/issue73/3882. html
So, lets look at some code! As learning the intricacies of Python would take more pages than can fit into this Pocketbook, we'll introduce you to Python through the use of an example program. If you find yourself craving more, we have provided a number of places at the end of this section where you can start looking.
Was this article helpful?
Soar Your Productivity Today. Master These Ultimate Productivity Techniques From The Worlds Most Successful People And Watch Your Results Soar Sky High In A Fraction Of The Time. These Hidden Techniques Will Literally Elevate You Up The Ladder Of Success By Helping You Achieve Much More In Less Time.