我写了一个很长、很整洁的 Python 类:
class Foo(object): | |
"""It is long and it has to deal | |
with PEP8 code width requirements| |
which are 72 characters for | |
comments and docstrings and 79 | |
for actual code. | |
""" | |
class_parm = 12 | |
pass # after several long, broken down|
# into several pieces, but in the|
# end *fit* lines of script, phew|
^
79 characters (say)
^
72 characters (say)
现在,事实证明我需要动态创建这个大类,以便它的一些静态成员在它的一个实例和另一个实例之间是不同的。简而言之,我需要把它变成这样的东西:
def make_foo(parm):
class Foo(object): | |
"""It is long and it has to d|al |
with PEP8 code width requirem|nts |
which are 72 characters for | |
comments and docstrings and 7| |
for actual code. | |
""" | |
class_parm = parm | |
pass # after several long, broken |own
# into several pieces, but in|the
# end *fit* lines of script, |hew
return Foo |
^
79 characters (say)
^
72 characters (say)
所以它会打破 PEP-8 的安排。我仍然可以通过审核所有内容并将线条分解成更多部分,以便它仍然适合。但这很乏味,我觉得这是我不应该担心的事情,因为它与我的实际编码活动没什么可看的。
我应该怎么办?有没有办法在不需要添加另一个缩进级别的情况下实现这一点?喜欢使用装饰器?或者有没有神奇的替代方法来分隔 python 块?可能是特殊字符?
我愿意编写符合标准且易于编辑的*.py
文件,但有时这是一个令人费解的目标:\