[Python-ideas] Dynamic code NOPing

Richard Oudkerk shibturn at gmail.com
Tue Dec 25 15:43:10 CET 2012


On 25/12/2012 7:23am, Andrew Grigorev wrote:
>
> class Factorial:
>      def __init__(self, n):
>          self.n  = n
>      def calculate(self):
>          return factorial(n)
>      def __str__(self):
>          return str(self.calculate)
>
> logging.debug("Factorial of %d is %s", 2**15, Factorial(2**15))

A more generic alternative would be

     class str_partial(functools.partial):
         def __str__(self):
             return str(self())

     logging.debug("Factorial of %d is %s",
                   2**15, str_partial(factorial, 2**15)))

-- 
Richard




More information about the Python-ideas mailing list