Learning how to program (using python)
Lesson 1: installing
On Linux
Type: sudo apt-get install python
Now python is installed.
- To run the interactive shell type: python
- To create a program, write it in vi (or some other editor), make sure its first line is
#!/usr/bin/python
and save it with a name ending in ".py"
To run the program type: ./program-name.py
Another way to run is to type: python program-name.py
On windows
- open http://python.org/getit/ in a new window.
- Click to download the windows installer for version 2.7.2 (or the latest version).
- Run the downloaded file. Click through the instructions (click next a bunch of times, then click finish).
Now python is installed.
- To run the interactive shell click START -> All Programs -> Python 2.7 -> IDLE (Python GUI)
- To create a program, write it in notepad (or some other editor), save it with a name ending in ".py" and double click it. The window that opens will dissappear as soon as the program ends.
Lesson 2: Hello World
This is a simple python program that prints "Hello World!"
In an editor (for example notepad or vi) create a file with the following contents:
#!/usr/bin/python
import sys
import time
sys.stdout.write("Hello World!\n")
while 1:
time.sleep(10)
Save it as a file named hello.py.
To run it:
- On Linux & Mac: in a terminal window type: python ./hello.py
- On Windows: double click the filename