April 27, 2010

Experiencing Python :: Part I

I was getting bored with working on similar tasks/projects. I had a drive in my mind to do something that can get myself charged up and on the other hand a new thing will be learned. Thinking about programming languages the first two things came in my mind was - Python and Ruby on Rails. I decided to start with python.




Installing : 
[I am on Red Hat Linux. I will add to this post or on a separate post the experience on my ubuntu and windows]
(1) I visited http://www.python.org/download/  and downloaded Python 2.6.5 as it was told there that if I was not sure of which version to get it will be the choice.

(2) After downloading, I have placed the Python-2.6.5.tar.bz2 to home/myUser folder and extracted it there. The folder name will be Python-2.6.5

(3) now in the terminal, i wrote the necessary commands and waited for them to be executed like as follows --

[root@localhost nagbaba]# cd Python-2.6.5
[root@localhost Python-2.6.5]# ./configure
... ... ... 
[root@localhost Python-2.6.5]# make
... ... ...
[root@localhost Python-2.6.5]# make install
... ... ...
(4) Now the installation has been completed. To go back, i typed -
[root@localhost Python-2.6.5]# exit

(5) Now python is installed and ready for use. To check the installation location
[root@localhost ~]# which python
it yields ---
/usr/local/bin/python


(6) To run python from command prompt we type --
[root@localhost ~]# python

(7) Then I opened my Eclipse 3.4.2. I went to
     Help >> Software Updates >> Available Softwares
In the textbox, i have written python and the IDE searched the available pydev plugins for eclipse. I checked the check boxes and installed them.


(8) Then in the "navigator perspective" i created a python project, but it wanted the path of the interpreter. I showed the path browsing (the path is /usr/local/bin/python as we have found it earlier).

(9) Then I right-clicked on the project icon at the navigator and clicked
new >> pydev module

(10) I left the package name blank and select src as the package. I named my project as 'testPY'. After creating the module, i searched google for "hello world" type code in python and luckily found one. I typed the following code and saved the file as testPY.py
def add(a,b):
     return a+b

print add(1,2)
(11) Then I right clicked the file on navigator and clicked
run as >> python run

in the small output window it gives the output 3.

I will be posting stuffs as I will be approaching to learn things. But for my irregular nature I guess it will not be an easy stuff.

4 comments:

  1. Fedora should have python installed by default. Any reason for installing it manually?

    ReplyDelete
  2. Nasim Vai,
    In my fedora (which was already installed before I have joined this office) I didn't find any prior installation. I was confused as I had heard fedora by default has perl, php and python installation. So I just decided to install it manually.

    ReplyDelete