Despite what assembly code and C coders might tell us, in the toolbox of any programmer, high-level languages have their place, and some of them are much more than a curiosity in computer science. Python appears to be the most interesting for those who want to learn something new and do real work at the same time, out of the many high-level languages we can pick from today. Its no-nonsense implementation of object-oriented programming, as well as its clean and clear syntax, make it a language that is enjoyable to learn and use, which is not true of most other languages.

You can learn how to write programs using command-line options, read and write to pipes, access environment variables, manage interrupts, read from and write to directories, build transient files, and write to machine logs in Python Training. In other words, instead of the same boring Hello, World! stuff, you can find recipes for writing individual applications.

Getting Started

To continue, now is the time to install the Python interpreter on your machine if you haven’t already. Download the latest Python distribution using packages compatible with your Linux distribution, such as rpm, deb, and tgz, which can be found on your Linux CD-ROM or on the internet. There should be no concerns if you follow the usual installation protocols.

I also suggest keeping a copy of the Python Library Guide on hand in case the examples given here are incomplete. In the same locations as the Python Tutorial, you will find it.

Scripts can be written in any text editor as long as it saves text in plain ASCII format and does not immediately insert line breaks when a line is longer than the editor’s window width.

Always begin your scripts with either

#! /usr/local/bin/python


#! /usr/bin/python

Adjust the section, keeping the first two characters (#!) untouched, if your system’s access route to the python binary is different. Be sure this is the first line of your script, not just the first non-blank line; this will save you a lot of time and irritation.
To render it executable, use chmod to configure the file permissions for your document. If the script is just for you, type chmod 0700; if you want to share it with someone in your community but not allow them to edit it, use 0750; if you want to grant anyone access, use 0755. To support with the chmod command, type chmod for man.

Reading Command-Line Options and Arguments

When we want to tell our scripts how to behave or transfer any arguments (file names, directory names, user names, etc.) to them, command-line options and arguments come in handy. These options and arguments can be interpreted by all programs if they wish, and the Python scripts are no exception.

The installation of suitable handlers comes down to reading the argv list and testing the alternatives and arguments that you want to remember in your script. There are a few choices for accomplishing this. Listing 1 is a basic option handler that recognizes typical -h, -help and —help options, and exits directly after the help message is shown when the options are identified. [source]-

Leave a Comment