0
So as I imagine you may have tried yourself, if we delete "return wrap" from from the end of the the definition for the "wrap" function we get a TypeError: 'NoneType', object is not callable... This happens because, although we have still defined the operations to be carried out by the "wrap" function, without telling it to "return wrap" there is no output created. And hence later when we try to call it there is essentially no output available to be called at that point. Also remember the tier like structure of how things are assigned, variables defined at lower levels, are basically not visible outside of where they are used. I think the course uses an example somewhere, where a variable used within a loop, is not visible, or basically has not been assigned in the larger code itself. Return is a way to push these variable or their results up to higher levels, or outside of the particular function, or chunk of code you have written them in.
20th Sep 2016, 4:52 PM
Matthew
0
I tried the following, it does exactly the samething. def decor(func): print("============") func() print("============") def print_text(): print("Hello world!") decor(print_text)
25th Sep 2016, 7:03 PM
Ying
0
I tried that too. What's the point of defining wrap function? Was it to show nested functions? Or is there a specific reason why you would advise the wrap function here?
1st Mar 2017, 9:51 AM
Carla Vidal
0
I tried that as well: def decor(func): print("============") func() print("============") @decor def print_text(): print("Hello world!") print_text() And I get: ============ Hello world! ============ Traceback (most recent call last): File "..\Playground\", line 12, in <module> print_text() TypeError: 'NoneType' object is not callable I guess the wrap function is doing something, but I don't understand it. Why do I get a TypeError?
1st Mar 2017, 10:01 AM
Carla Vidal