Monday, December 10, 2012

Installing PyDev in Eclipse (Python IDE)




Programming Python is so much fun in Eclipse using the PyDev Plugin. If you've never programmed in an IDE (Integrated Development Environment) then your going to be pleasantly surprised. Eclipse is a good and powerful IDE that is meant to be a Java IDE. But it can be extended with plugins to support several other languages. Eclipse requires the Java Runtime Environment in order to run. The following screen shot is an example of the sort of error you get when you try to run Eclipse without first installing the JDK.


A Missing Java Runtime Engine (JRE) will prevent Eclipse running
Running Eclipse is simple. You just run the eclipse.exe executalbe and choose a workspace. 
You Then :
  • Choose Help
  • Click "Install New Software"
  • Click Add and in the location box type : http://pydev.org/updates
  • In the "Work With" text box at the top, type : PyDev and then select PyDev in the checkbox below.



Choose Help - > Install New Software -> Click Add, In the location box type http://pydev.org/updates. Type Pydev in the "Work with" box and select PyDev by clicking the checkbox

Agree to the license





After PyDev installs successfully you will be able to create PyDev Projects. Select 
Starting an new Python Project in PyDev

Your code won't run  before you configure an interpreter to run it.Auto config is an easy way to do so.
PyDev must be told where the python interpreter is on your computer. Fortunately PyDev can easily detect Python Interpreters using the Auto Config option 







More tutorials on the way. To show how PyDev works and how to use the debugger.


PyDev + Eclipse : A good Python IDE for beginners

Installing Pydev in Eclipse

Installing PyDev is straight forward. When I installed it I went through the following steps:
  1. Go to www.eclipse.org/downloads/ and you;ll find several different flavors of the Eclipse IDE each targeted to different users. 
  2. Download the Eclipse Classic 4.2.1 in the version that suits the architecture of your machine(i.e. either 64-bit or 32-bit.)
  3. Run Eclipse and choose 'Help' 
  4. Choose  "Install new software"
  5. Click Add
  6. In the location box type "http://pydev.org/updates"
  7. Typed "Pydev" in the "Work with" text box
  8. Select the PyDev for eclipse checkbox
  9. Uncheck the "contact all update sites during install to find required software". Leaving it checked stalls the installation process for some unknown reason.

Python 3.0

Python 3.0 was released in December , 2008 and is referred to sometimes as Python 3000 or Py3k. It is a new version of the language and is incompatible with the 2.x line of releases. The language is mostly the same but many details  how built in objects like dictionaries  and strings have been changed considerably and a lot of deprecated features have been removed. Also, the standard library has been reorganized in a few key places.

Saturday, December 8, 2012

Some String Operations in Python

Finding the length of  a string 

 >>> message = "new string"
>>> len(message)
10
 

 So to find the length of string x you simply use len(x) . The function len() gets called with x as a parameter and returns the length as a return value. 10 in this case.



Accessing string elements by Index

 >>> message = "new string"
 >>> print(message[0])
n
>>> print(message[1])
e
>>> print (message[2])
w
 

All stuff in the string (i.e. couple of letters,numbers, characters strung to each other) can be accessed individually using the [] operator . The first character(letter) is at index 0 or numbered by 0. Hence print(message[0]) gave us the first letter in the string message which is 'n'. Moving to the next index(number) moves us to the next character(letter). This is really simple stuff.


Going through all letters of a string 

>>> for letter in message:
    print(letter)
n
e
w

s
t
r
i
n
g


This is a for loop and goes through all letters in  the string message.


Testing if two strings match( are the same)

>>> message = "new string"
>>> m = "new string"
>>> if  m == message:
    print("They match")

   
They match