Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old September 4th, 2008, 04:45 PM
Aigars Aigars
Guest
 
Posts: n/a
Default Function decorators

Good day all,

I am learning Python and came up to decorators.

Thequestion is: Why does function FoodList return value None?

The code in attachment.
Thank you,
Aigars
  #2  
Old September 4th, 2008, 04:55 PM
David C. Ullrich
Guest
 
Posts: n/a
Default Re: Function decorators

In article <mailman.493.1220542975.3487.python-list@python.org>,
Aigars Aigars <srad@inbox.lvwrote:
Quote:
Good day all,
I am learning Python and came up to decorators.

The question
Quote:
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.
Quote:
>
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
Quote:
Thank you,
Quote:
Aigars---------------------------------------------------------------------
[Image]
--
David C. Ullrich
  #3  
Old September 4th, 2008, 05:05 PM
Diez B. Roggisch
Guest
 
Posts: n/a
Default Re: Function decorators

Aigars Aigars schrieb:
Quote:
Good day all,
>
I am learning Python and came up to decorators.
>
The question is: Why does function FoodList return value None?
>
The code in attachment.
Because the __call__ in Logger doesn't return the value of self.func.

Diez
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles