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



















Wednesday, November 28, 2012

Introduction to the Python Programming Language


 

What is Python and Why you should care

If you are into computers and haven't heard about Python then you're probably living under a rock or haven't had any contact with civilization in a long while.  Python is a new and very sexy programming language that is so cool and so powerful its used by NASA and Google and can do a million things in a single page of code.

Most people that like technology and computers like python for several reasons. Python is very concise you can do a lot in a few lines of code. The built in features of the language and library are very extensive and get a lot done. 

If you want to pick a programming language to learn for the heck of it or to get things done quickly and without spending the rest of your life in a debugger then Python is the way to go

The Interpreter 

Now as you already might know any programming you do is a form of communication between a human being and a machine. Computers only natively understand bits and bytes and memory addresses and stuff you'll learn about when you try to learn Assembler. Unfortunately trying to solve a real-world problem while thinking of bits and bytes and registers and flags doesn't get you very far. Computer scientist invented the idea of programming languages to make the lives of programmers much easier. Now you tell a computer what to do in a certain "Programming Language" and a piece of software (called the interpreter in Python)will do the translating from the human high-level view of things to the bits and bytes and memory address view of things that computers understand on their own without outside intervention.

 Where to get Python From

In order for your computer to understand Python programs you'll have to download the python interpreter. The latest of version as of this writing is 3.3.0 . The interpreter is available for Windows,Mac and Linux and comes in a 64-bit and 32-bit versions.

If you're running windows like me, just download the python-3.3.0 Windows Installer (19.1 MB)

and click next a couple of times. The Python 3.3.0 Installer will install to C:\Python33 and add program files folder. This folder should look something like this:

 

 The windows Installer brings you the Python interpreter as well as the documentation that will show you the rules of the language.

So open the IDLE python GUI or the Python command line and start entering little programs and seeing how the work interactively. 

Examples of working in the Python GUI 
You'll notice a >>> prompt that tells you that Python is waiting for you to enter something so it can work on.

So if you type this :

>>> m = "this is my new life"
>>> len(m)


You'll get this
19

Which is the size of the string called m.

Reading through the Python manuals will give you all the information you need to start programming effectively.
The Python 3.3 manual is divided into the following major sections:
 
  1. Tutorial
  2. Library Reference
  3. Language Reference
As well as other more advanced stuff you'll need as you progress into more advanced programming.