Reputation: 19
I understand the idea that we follow our own naming convention, but is this totally so? For instance a function/variable name cannot begin with a number but can include 'special' characters, right? However this:
@methodtrace(utils.logger)
raises questions for me. Are the @
and .
significant? I have read What is the naming convention in Python for variable and function names?
Upvotes: 1
Views: 104
Reputation: 122032
This is not a matter of coding style (which for Python is defined in PEP-8), but of syntax. What you have posted is not a single name. It means:
@methodtrace(utils.logger)
^ decorate the following function
^ with the result of calling the function methodtrace
^ with a single argument, the logger attribute of utils
A valid Python identifier is defined in the documentation - it must start with a letter (upper- or lower-case) and then include zero or more letters or numbers. The @
is syntactical sugar for decorating a function (see What does the "at" (@) symbol do in Python?), the parentheses are syntax for calling a function/method and the .
is used for access to the attributes of an object.
Upvotes: 3