Thursday, August 28, 2014

[Python] Get source of the module function



 >>> import inspect  
 >>> import fractions  
 >>> print (inspect.getsource(fractions.gcd))  
 def gcd(a, b):  
   """Calculate the Greatest Common Divisor of a and b.  
   Unless b==0, the result will have the same sign as b (so that when  
   b is divided by it, the result comes out positive).  
   """  
   while b:  
     a, b = b, a%b  
   return a  

No comments:

Post a Comment