[Tutor] Create Logging module

Peter Otten __peter__ at web.de
Thu Aug 1 12:36:53 EDT 2019


Sinardy Xing wrote:

> following is my main app
> 
> -- start here--
> from loggingme import logme
> 
> def say_hello(name, age):
>         print('Hello {}, I am {}'.format(name, age))
> 
> #say_hello=logme(say_hello('Sinardy'))
> @logme
> say_hello('Tonny', 8)

Isn't this a SyntaxError? You can decorate functions, not function calls:

When Python finds a syntax error in your main script it won't proceed to run 
it and thus the bugs in modules that would be imported if the code were 
executed don't matter at this point.

Try

@logme
def say_hello(name, age):
        print('Hello {}, I am {}'.format(name, age))

say_hello('Tonny', 8)




More information about the Tutor mailing list