Python-PEP8挂起缩进错误消息

时间:2019-07-13 12:59:37

标签: python-3.x pep8

对于以下代码,我得到以下错误:

config = {
    'bucket': json.loads(record['body'])
                ['Records'][0]['s3']['bucket']['name'],
    'key': json.loads(record['body'])
           ['Records'][0]['s3']['object']['key']
}
E131 continuation line unaligned for hanging indent
                              ['Records'][0]['s3']['bucket']['name'],

E131 continuation line unaligned for hanging indent
                           ['Records'][0]['s3']['object']['key']

我尝试了包括以下内容在内的一些选项-但它不起作用:

config = {
    'bucket': json.loads(
                        record['body']
                        )
                        ['Records'][0]['s3']['bucket']['name'],
    'key': json.loads(record['body'])
           ['Records'][0]['s3']['object']['key']
}

我在行尾也尝试过+ \,但也无法正常工作

2 个答案:

答案 0 :(得分:1)

为了符合PEP8,以下适用于这种情况:

The minimum distance between the array of points entered is -2147483648.

答案 1 :(得分:0)

尝试一下,应该是这种格式

config = {
    'bucket': json.loads(record['body'])['Records'][0]['s3']['bucket']['name'],
    'key': json.loads(record['body'])['Records'][0]['s3']['object']['key']
}

或在此

config = {
    'bucket': json.loads(record['body']) \
                ['Records'][0]['s3']['bucket']['name'],
    'key': json.loads(record['body']) \
           ['Records'][0]['s3']['object']['key']
}

有关更多信息,请检查What is PEP8's E128: continuation line under-indented for visual indent?问题。