python 中已被系统库占用的变量名的命名约定是什么
What's the naming convention in python for variable name already taken and occupied by system library
有时我需要使用像max
或len
这样的变量名,但它们不知何故被python库方法占用了。我应该只使用 _max
还是 max_
?
这些变量命名风格的转换是什么?
没有这样的约定,至少在 PEP 8 中没有,PEP 8 中提到的可能适用的内容如下:
If a function argument's name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thus class_ is better than clss. (Perhaps better is to avoid such clashes by using a synonym.)
来自pep8 official documentation:
single_trailing_underscore_: used by convention to avoid conflicts with Python keyword, e.g.
Tkinter.Toplevel(master, class_='ClassName')
有时我需要使用像max
或len
这样的变量名,但它们不知何故被python库方法占用了。我应该只使用 _max
还是 max_
?
这些变量命名风格的转换是什么?
没有这样的约定,至少在 PEP 8 中没有,PEP 8 中提到的可能适用的内容如下:
If a function argument's name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thus class_ is better than clss. (Perhaps better is to avoid such clashes by using a synonym.)
来自pep8 official documentation:
single_trailing_underscore_: used by convention to avoid conflicts with Python keyword, e.g.
Tkinter.Toplevel(master, class_='ClassName')