In this article series I will try to learn about and investigate the possibilities of Python. I will come up with solutions to my problems that I meet along the road, and I will try to teach you as much as I am teaching myself. In this first article I will prepare for myself a base of tools and information that I need to use frequently throughout the programming process.
The most important things first, a cheat sheet is a useful thing, even if you’re an expert. You never know everything, so these links will be my personal starting point and reference throughout my article. In addition, Google can help us find information about topics that usually will take some time to understand.
Second, I am an expert in Java programming, So keep in mind that I may fall into great bottomless pits. Please be kind enough to tell me about those pits before I am eaten by the great Yeti.
I will try to keep a loose tone, even if my main language is not English. But I am used to both writing and speaking English daily so personally I believe it will work out!
So, lets install Python shall we? If you have linux it is probably installed already. If not, install it using your package manager. In ubuntu: sudo apt-get install python. If you have windows (bless you mate) then you would like to download python now!
>>> this_is_a_number = 1
>>> print this_is_a_number
1
>>>
It can’t get more easy than this. This is an example on how to use to the command line interactive interpreter. In linux you type python to open up the console. In windows Python executable is usually installed in c:python26, but you can change this in the installation process.
In windows and linux you can make script files containing lines to be executed by python. A typical script can have any name and ending, and can look like this (in linux):
#! /usr/bin/env python
name = "Jarl"
print name
In linux this script can be executed, if the file is executable, with ./myscript.py. The file does not have to end with .py
In windows you can execute the files by opening up the command line, and enter c:pathtopythonexecutable myscript.py
Now we know how to type python in interactive mode as well as in scripts! Lets take a look at the tutorial for python 2.6!
In the next article I will take a look on file handling! Stay put!
0 Response to “A dive into Python – part 1”