Google-styleguid
naming
Tip
Module_name, Package_name, ClassName, Method_name, Exceptionname, Function_name, Global_var_name, Instance_var_name, Function_parameter_name, Local_var_name. names that should be avoided
1. Single character name, except for counters and iterators.
2. The hyphen (-) in the Package/module name (-)
3. A name that begins and ends with a double underline (python retention, for example, __init__)
Naming Conventions
1. The so-called "internal (Internal)" means that only the modules are available, or that they are protected or private within the class.
2. The beginning of a single underline (_) indicates that the module variable or function is protected (not included when using import * from).
3. An instance variable or method that starts with a double underline (__) represents a private class.
4. Put the relevant classes and top-level functions in the same module. Unlike Java, there is no need to limit a class to a module.
5. A word that starts with a capital letter for the class name (such as capwords, Pascal style), but the module name should be underlined in lowercase (such as lower_with_under.py). Although there are already many existing modules using names like capwords.py, this is discouraged because the module name happens to be in line with the class name.
the code recommended by the father of Python Guido
Main
Tip
Even a file that is intended to be used as a script should be imported. And a simple import should not cause this script's main function (main functionality) to be executed, which is a side effect. The main function should be placed in a main () function.
In Python, Pydoc and unit tests require that the module be imported. Your code should always check if name = = 'main' before executing the main program so that when the module is imported, the main program
def main (): ...
if __name__ = = ' __main__ ':
Main ()
When the top-level generation block is imported, it will be executed. Be careful not to call functions, create objects, or perform actions that should not be performed when using Pydoc.
Https://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_style_rules/ Python Naming conventions
1, package name, module name, lowercase; multiple words, underline split
login.py
user_login.py
2, the class name, the first letter capital, many words, with the hump
Class Login:
class Userlogin:
3, method name, lowercase, multiple words, underline segmentation
def login:
def user_login:
4, variable name, lowercase, multiple words, underline segmentation
user = user
5, constant name, uppercase, multiple words, underline split
Max_overflow
6, parameter name, all lowercase
def login (self, user, password):