Calculate time difference in minutes

Thursday, June 13, 2013

Below code will explain how to find a difference in the minute,
if you have two dates, then you can find the difference of the time using divmode function of python
 >>> import datetime  
 >>> end =  
 >>> start =  
 >>> diff  
 datetime.timedelta(0, 7, 424199)  
 >>> diff = start - end  
 >>> divmod(diff.days * 86400 + diff.seconds, 60)  
 (0, 7) # 0 minutes, 7 seconds  

Creating generators objects in python

Sunday, June 2, 2013

What is Generator?

A generator is a function which can stop whatever it is doing at an arbitrary point in its body, return a value back to the caller, and, later on, resume from the point it had `frozen' and merrily proceed as if nothing had happened (link) . Here is a simple example: 

if you write 

x = [n for n in foo if bar(n)]

you can get the list object assigned to the x.

x=(n for n in foo if bar(n))
you can get out the generator and assign it to x. Now it means you can do