A single underscore before a name is used to specify that the name is to be treated as “private” by a programmer. It’s kind of a convention so that the next person (or yourself) using your code knows that a name starting with _ is for internal use.
a name prefixed with an underscore (e.g. _spam) should be treated as a non-public part of the API (whether it is a function, a method or a data member). It should be considered an implementation detail and subject to change without notice.
Otherwise, a single leading underscore isn't exactly just a convention: if you use from <module/package> import *, none of the names that start with an _ will be imported unless the module’s/package’s __all__ list explicitly contains them.
In file utils.py and common.py, there are some underscore(
_
) before some variable. For example:Then, why name them as that?
Single Underscore Before a Name
A single underscore before a name is used to specify that the name is to be treated as “private” by a programmer. It’s kind of a convention so that the next person (or yourself) using your code knows that a name starting with _ is for internal use.
As the Python documentation says:
Otherwise, a single leading underscore isn't exactly just a convention: if you use
from <module/package> import *
, none of the names that start with an _ will be imported unless the module’s/package’s__all__
list explicitly contains them.Ref:
Underscores in Python
What is the meaning of a single- and a double-underscore before an object name?