Function decorators

David C. Ullrich dullrich at sprynet.com
Thu Sep 4 11:52:46 EDT 2008


In article <mailman.493.1220542975.3487.python-list at python.org>,
 Aigars Aigars <srad at inbox.lv> wrote:

> Good day all,

I am learning Python and came up to decorators.

The question 
> is: Why does function FoodList return value None?

Because the function doesn't return anything, and in Python
a function that doesn't explicitly return anything returns None.

>

The code in attachment.


Thanks for not just pasting it into the post, like so:

class Logger:

   def __init__(self, function):

      self.func = function



   def __call__(self, *args, **kwargs):

      print "Function %s called with args = %s, kwargs = %s" % 
(self.func.__name__, str(args), str(kwargs))

                self.func(*args, **kwargs)

       

@Logger

def FoodList(a, b, c="spam"):

   text  = "Food is %s, %s, %s" % (a, b, c)

   print text

   return text





if __name__ == "__main__":

   a = FoodList("eggs", "potatoes")

   print a

> Thank you,

> Aigars---------------------------------------------------------------------
> [Image]

-- 
David C. Ullrich



More information about the Python-list mailing list