Why use Python?
Here at ECTC, we offer three options for the CIT students. Python is a language that benefits each of the IT students. For the networking students, Python provides a tools that allows for automation of system shell functions. Much of what networking students do revolves around the setting up of computer networks and learning to maintain these networks effectively. Python can help! Many of the tasks in management of the network are tedious and often menial. If the option of knowing a language that can automate these tasks, why not learn it to help minimize the total work spent on these easy tasks?
And what about web development? Web development is one of python’s strong points. You can only do so much with HTML / CSS and JavaScript. What if you want a data driven website, something like Amazon or eBay or Facebook? Python can help you create these dynamic web pages by connecting to a database where information about users or items are stored.
Python is also a good tool for the programming option. In all three OSes, it can be used as a stand alone programming language that can create complex GUI applications. Overall, Python is a good choice simply because it can be used for all three options, and it is relatively simple to learn in comparison to many other languages.
Installing Python
If you use Linux, Unix, or Mac OS X (a derivation of Unix), you likely have python installed already, just open up your terminal and type “python”. This will open up python for you. You should check the version to determine if you are using the most recent version (as of this writing, 3.2).
Most people use Windows however, which means you will need to install python on your computer. You can download python on their website: http://www.python.org/. Just go to the download page and download the latest version’s MSI installer for your version of windows (x86 or x86-64) and just run the install wizard. You can read the documentation online if you want to change various configuration setting on python, however for this class, the standard python installation should be more than enough.
This version comes with a python command line application, which runs from within command prompt in windows. It also comes with IDLE, which allows you to run python from within a window of the OS. Some people may prefer using the command prompt instead of opening up an entirely different application (The instructions below are for use in command prompt). For this we can change the Environment variables. Go to Control Panel > System and Settings > System > Advanced System Settings (off to the left). This will bring a display window which has a button called “Environment Variables”. Just find the Path variable and at the end add “C:\Python32″ (or the path to the python application location). REMEMBER, path variables are separated by semicolons!
Running Python Scripts
Let’s write a simple python script to test our install and learn how to run the script. You can write python scripts in your favorite text editor (Notepad will work just fine, though I would recommend something like Crimson/Emerald Editor in Windows since it adds syntax highlighting). For now, just copy and paste this program:
print("Hello World!")
Be careful that the program does not add any tabs. We’ll learn that tabbing in python is extremely important and can cause code to fail if tabbing is not done in the code. Save this file in some location saving it with the .py extension.
To run this code, open up your terminal or command prompt and change to the directory that the file has been saved. To run the file, type “python filename.py” where filename.py is the name of the file that you saved. This should give you the expected “Hello World!” output.
More on running python
If you want to know more about running scripts in python, there are several flags that can be used. You can check out the man pages for python to learn more. NOTE: We will see the -c flag used when we start discussing modules. You can check the manual pages for python at: http://www.linuxmanpages.com/man1/python.1.php.
Now, why would I want to install a snake on my computer?
Thanks, I have Python installed on both my linux box and win7