Google Open source project style guide: http://zh-google-styleguide.readthedocs.io/en/latest/reference: http://www.cnblogs.com/zhanglianbo/p/ 5664997.html naming
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
- Single-character names, in addition to counters and iterators.
- Hyphen (-) in Package/module name
- A name that begins and ends with a double underscore (python reserved, for example __init__)
Naming conventions
- The so-called "internal (Internal)" means that only modules are available within the module, or that they are protected or private within the class.
- Starting with a single underscore (_) indicates that a module variable or function is protected (not included when using import * from).
- An instance variable or method that begins with a double underscore (__) represents a private in-class.
- Place related classes and top-level functions in the same module. Unlike Java, there is no need to restrict a module to a class.
- Words that begin 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 that use a name similar to capwords.py, it is now discouraged because if the module name happens to coincide with the class name, it can be confusing.
Python's father Guido recommended specification
Type |
| Public
Internal |
Modules |
Lower_with_under |
_lower_with_under |
Packages |
Lower_with_under |
|
Classes |
Capwords |
_capwords |
Exceptions |
Capwords |
|
Functions |
Lower_with_under () |
_lower_with_under () |
Global/class Constants |
Caps_with_under |
_caps_with_under |
Global/class Variables |
Lower_with_under |
_lower_with_under |
Instance Variables |
Lower_with_under |
_lower_with_under (Protected) or __lower_with_under (private) |
Method Names |
Lower_with_under () |
_lower_with_under () (protected) or __lower_with_under (private) |
Function/method Parameters |
Lower_with_under |
|
Local Variables |
Lower_with_under |
|
Python Naming conventions