Differences between class and function decorator

M

mk

Hello everyone,

I rewrote an example someone posted here recently from:
def new_meth(*args, **kwargs):
print method.func_name
return method(*args, **kwargs)
return new_meth
def f2():
pass
f2


...to:
def __init__(self, func):
self.name = func.func_name
self.func = func
def __call__(self):
print self.name
return self.func

def f():
pass
f
<function f at 0x017CDA70>

Note that function decorator returned None, while class decorator
returned function.

Why the difference in behavior? After all, print_method_name decorator
also returns a function (well it's a new function but still a function)?

Regards,
mk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top