Saturday, January 26, 2013

First python program

I am new to python, so I first want to create the traditional "hello world" program in python and see if it works.
On my raspberry pi, python was already installed and added to the path.
There are different Version installed (standard 2.7 and the newer 3.2). Check your version:
python --version
Open an editor and type the following program:
print "hello world"
Save as "". It can be executed either by calling the python binary or making the file executable (asuming you are in the same directory as the python script file):
chmod +x   //sets the executable flag
Or if you want to run it as phyton 3.2:
This will output an error, because in the 3.x version of python the "print" command is a function and so we have to use it with parenthesis like this:
print("Hello world")
 Now it should work and print "Hello world" to stdout. Nice.

1 comment: