2016-08-22 170 views
3

我的代码:PEP 8 E211问题引发。不知道为什么

if 'certainField' in myData['meta']['loc']: 
    something = myData['meta'] \   <- PEP8 E11 raised for this 
    ['loc'] \        <- PEP8 E11 raised for this 
    ['certainField'] \      <- PEP8 E11 raised for this 
    ['thefield'] 

的代码按预期工作。但PEP 8 E211是针对第二,第三和第四线索提出的whitespace before '['

我不明白。我怎样才能格式化这个PEP 8?

回答

1

你可以用你的声明为括号并删除\

if 'certainField' in myData['meta']['loc']: 
    something = (myData['meta'] 
       ['loc'] 
       ['certainField'] 
       ['thefield']) 


这里是包皮过长的线路摘录形式 PEP 8

包皮过长行的首选方法是通过在括号,括号和大括号内使用Python的隐含行继续。通过在圆括号中包装表达式,可以将多条线分成多行。这些应该优先使用反斜杠进行续行。

反斜杠有时可能仍然适用。例如,long, 多个带-statements的不能使用隐式延续,所以 反斜杠是可以接受的:

相关问题