如何按照 PEP8 规则缩写维度?

how to abbreviate dimension following the PEP8 rules?

我必须添加创建 3D 纹理的功能。 我在整个模块中使用蜗牛案例。

我的选择是:

def texture_3d(...):
    pass

def texture_3D(...):
    pass

def texture3D(...):
    pass

函数的名称应该是什么?

对意见感兴趣:哪个看起来更好。我需要一些对其他模块的参考才能看到最佳实践。

请至少提及 1 个具有相似功能的模块。

来自PEP-8

Method Names and Instance Variables

Use the function naming rules: lowercase with words separated by underscores as necessary to improve readability.

这向我表明,您的第一个选项是三个选项中最符合要求的。

简答texture_3d.

PEP-8 说 about function names:

Function names should be lowercase, with words separated by underscores as necessary to improve readability.

mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.

由于 "texture" 和“3d”是两个不同的词,最好在它们之间加上下划线。此外,函数名称应为小写,因此 3D 不允许

PEP 8 states 小写,函数名称 单词 之间用下划线分隔。现在,因为如果 3d/3D 是一个实际的词,你会在名称 texture_3dtexture3d 之间遇到冲突(d小写)。

查看许多 numpy 函数,例如,lagval3d, laggrid3d, hermegrid3d 名称 texture3d 看起来是个不错的选择。

the matplotlib docs 中搜索相似名称会产生 <name>3d<name>_3d 之间的混合结果。

简而言之,基于两个主要软件包,这两个名称似乎都可以接受。归结为两者之间的个人选择。

与其单靠人的意见,不如问问马? (如“从马口中获取”。)换句话说,使用 pylint.

我修改了您的代码以减少生成的消息。

''' some information here'''

def texture_3d(parameters):
    ''' a docstring'''
    return parameters

def texture_3D(parameters):
    ''' a docstring'''
    return parameters

def texture3D(parameters):
    ''' a docstring'''
    return parameters

pylint 的结果是:

************* Module temp
C:  7, 0: Invalid function name "texture_3D" (invalid-name)
C: 11, 0: Invalid function name "texture3D" (invalid-name)

------------------------------------------------------------------
Your code has been rated at 6.67/10 (previous run: 5.00/10, +1.67)

只剩下选项 texture_3d