Python programming for beginners

Business

Despite what assembly code and C encoders may tell us, high-level languages ​​have their place in every programmer’s toolbox, and some of them are much more than a computing curiosity. Of the many high-level languages ​​we can choose from today, Python seems to be the most interesting for those who want to learn something new and do real work at the same time. Its no-nonsense implementation of object-oriented programming and its clean, easy-to-understand syntax make it a language that is fun to learn and use, which is not something we can say about most other languages.

In Python Training, you will learn how to write applications that use command line options, read and write to pipes, access environment variables, handle interrupts, read and write to files, create temporary files, and write to system logs. In other words, you’ll find recipes for writing real apps instead of boring old Hello, World! things.

Starting

For starters, if you haven’t installed the Python interpreter on your system, now is the time. To make that step easier, install the latest Python distribution using packages compatible with your Linux distribution. rpm, deb, and tgz are also available on your Linux CD-ROM or online. If you follow the standard installation procedures, you shouldn’t have a problem.

I also recommend that you have the Python Library Reference handy; you may want it when the explanations provided here do not meet your needs. You can find it in the same places as the Python Tutorial.

You can create scripts with your favorite text editor as long as you save the text in plain ASCII format and do not automatically insert line breaks when the line is longer than the width of the editor window.

Always start your scripts with

#! / usr / local / bin / python

gold

#! / usr / bin / python

If the path to the Python binary on your system is different, change that line, leaving the first two characters (#!) Intact. Make sure this line is actually the first line in your script, not just the first non-blank line, as it will save you a lot of frustration.

Use chmod to set file permissions on your script to make it executable. If the script is just for you, type chmod 0700 scriptfilename.py; if you want to share it with other members of your group but not let them edit it, use 0750 as the chmod value; if you want to give access to all the others, use the value 0755. For help with the chmod command, type man chmod.

Reading command line options and arguments

Command line options and arguments are useful when we want to tell our scripts how they should behave or pass them some arguments (file names, directory names, user names, etc.). All programs can read these options and arguments if they want to, and their Python scripts are no different.

Implementing the appropriate handlers comes down to reading the argv list and checking the options and arguments that you want your script to recognize. There are several ways to do this. Listing 1 is a simple options handler that recognizes the common options -h, -help, and –help, and when found, exits immediately after displaying the help message.[source]- https://www.linuxjournal.com/article/3946

Leave a Reply

Your email address will not be published. Required fields are marked *