1

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?

Community
  • 1
  • 1
P.Holmes
  • 19
  • 5
  • You can follow your own convention ([PEP-8](http://www.python.org/dev/peps/pep-0008/) preferred), but can still only use [valid Python identifiers](https://docs.python.org/2/reference/lexical_analysis.html#identifiers). `@` is used (from 2.4) for function decorators and (from 3.5) matrix multiplication, and `.` is for attribute access. – jonrsharpe Oct 08 '15 at 11:15
  • Possible duplicate of [What does the "at" (@) symbol do in Python?](https://stackoverflow.com/questions/6392739/what-does-the-at-symbol-do-in-python) – sophros Jul 16 '19 at 13:31

1 Answers1

3

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.

Community
  • 1
  • 1
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437