相关疑难解决方法(0)

编码风格(PEP8) - 模块级别"dunders"

"Dunder"(定义d ouble 得分):http://www.urbandictionary.com/define.php?term=Dunder


我有根据的模块级"dunders"(如放置的问题__all__,__version__,__author__在Python代码等).

这个问题向我走来,通过阅读而PEP8,看到这个堆栈溢出问题.

接受的答案是:

__author__ 是一个全局"变量",因此应该出现在导入之下.

但是在PEP8部分模块级别的dunder名称中我读了以下内容:

模块级"dunders"(即名称具有两个前缘和两个纵下划线),例如__all__,__author__,__version__等应被放置在模块文档字符串之后,但在除了从任何导入语句__future__进口.Python要求future-imports必须在除docstrings之外的任何其他代码之前出现在模块中.

作者还给出了一个代码示例:

"""This is the example module.

This module does stuff.
"""

from __future__ import barry_as_FLUFL

__all__ = ['a', 'b', 'c']
__version__ = '0.1'
__author__ = 'Cardinal Biggles'

import os
import sys
Run Code Online (Sandbox Code Playgroud)

但是当我将上述内容放入PyCharm时,我看到了这个警告(也见截图):

PEP8:模块级别导入不在文件顶部

PyCharm无视PEP8?

问题:使用双下划线存储这些变量的正确方法/位置是什么?

python pep8 pep pycharm

18
推荐指数
1
解决办法
2744
查看次数

标签 统计

pep ×1

pep8 ×1

pycharm ×1

python ×1