0

Anyone know why it is that its necessary that in a python first class function that embeds another, it is necessary to return the embedded function else an instance of the first class function is of type None?

Here's an example:

def logger(msg):
     def log_message():
         print(f'Log: {msg}')


log_hi = logger('Hi')
print(log_hi)
>>> None

type(log_hi)
>>> <class 'NoneType'>

log_hi()
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 TypeError: 'NoneType' object is not callable
allan e
  • 23
  • 1
  • 5

0 Answers0