Getting Started with Python Programming and Scripting in Linux – Part 1

It has been said (and often required by recruitment agencies) that system administrators need to be proficient in a scripting language. While most of us may be comfortable using Bash (or other shell of our choice) to run command-line scripts, a powerful language such as Python can add several benefits.

Learn Python Programming Scripting in Linux

To begin with, Python allows us to access the tools of the command-line environment and to make use of Object Oriented Programming features (more on this later in this article).

Being so easy to learn, so vastly used, and having a plethora of ready-to-use modules (external files that contain Python statements), no wonder Python is the preferred language to teach programming to first-year computer science students in the United States.

In this 2-article series we will review the fundamentals of Python in hopes that you will find it useful as a springboard to get you started with programming and as a quick-reference guide afterwards. That said, let’s get started.

Python in Linux

Python versions 2.x and 3.x are usually available in most modern Linux distributions out of the box. You can enter a Python shell by typing python or python3 in your terminal emulator and exit with quit():

By the way, it is important to note that although versions 2.x are still used, they are not actively maintained. For that reason, you may want to consider switching to 3.x as indicated above. Since there are some syntax differences between 2.x and 3.x, we will focus on the latter in this series.

Another way you can use Python in Linux is through the IDLE (the Python Integrated Development Environment), a graphical user interface for writing Python code. Before installing it, it is a good idea to perform a search to find out what are the versions available for your distribution:

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

Seriously Gabriel? That’s like posting “If you’d like to increase space on your hard drive, you can use “rm -rf /” and then saying that you” didn’t actually recommend it.” when someone points out it deleted their entire hard drive.

Novice Linux users come to sites like this and follow directions; “clarifying” potentially damaging instructions after the fact isn’t very useful. You should, at the very least, insert a clear cautionary statement. Better yet, move this “suggestion” and the “clarification to the suggestion” adjacent to each other AND include a cautionary statement that it can break packages on some common distros.