Saturday, March 31, 2012

Exception Handling in Python

 Mechanism of Exception in Python
Exception !!! the term when occurs in code, may crash your code, make your program quit undesirably, forcefully. This exception arises due to the program written like DivideByZeroException, IOError etc. Each computer language has its own way to tackle the Exceptions. Python is no longer an exception in this regards. It has a beautiful Try-Except mechanism to deal with run time errors in the code.Following is the syntax
#1 code goes here
#code goes here to handle the situation
#in case you may want some operations happen ,use Finally block
#code goes here to perform operations like memory handling, file closing etc
  1. This refers to single line comment in Python [back]
  2. Dont FORGET to put : at the end of try-except and finally statements or interpreter gives you error 
Remember when an error or exception occurs , there comes track-stack as output. It states the type of error,along with certain other information  about the error. Also it defines the line where exception occurs . 
Also do try to use try-except block in your code always ,in order to provide security to code .Also some time it happens the after closing the file in python,it crashes ,thereby the data may lost.To protect code from such situation ,it is Strongly recommended to use try-except block always.Have a happy coding

Thursday, March 29, 2012

Basics of Python

It shows the data structure concept of a dicti...
It shows the data structure concept of a dictionary in python (Photo credit: Wikipedia)
Basics of Python -A look
Learning python is not a tough work if you know what are programming languages,had deal with some of them. When I started working with python language,today professionally, I found it to be easy to begin with python docs itself. The docs are fully functional and easy to get in . The main thing in python to learn is Data structures
the main data structures are -dictionary ,Sets,tuple,List,stacks,Queue. The Dictionary is what you are watching in the image here. It is based on Key:Value relationship.
Also the fastest data structures in language are dictionaries itself ,retrieve data from a list of millions of data ,in seconds with the help of key. To create  a dictionary in python ,the following syntax is used :- 

d=('ABC':111 )
where ABC refers to Key and 111 refers t its values
One important thing we can have here in dictionary is Link comprehensions.It is somewhat like the following code 

d=(x,x**2) for x in (2,4,6)
this code is easy to read an manipulate as well .hence the programming deals with such code also .

Saturday, March 17, 2012

Python Programming language Basics

Introducing another great language this time -Python.Yeah it is good too because it can deal with bigger challenges including making a web crawlers also.Python is a scripting language where there is no compiler working at all.All the execution is done by interpreter alone.So this reduces time in running an application/program in python.