Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Lambda python中返回之前检查字典中的值_Python_Amazon Web Services_Aws Lambda - Fatal编程技术网

如何在Lambda python中返回之前检查字典中的值

如何在Lambda python中返回之前检查字典中的值,python,amazon-web-services,aws-lambda,Python,Amazon Web Services,Aws Lambda,结果如下 result = {'took': 5, 'timed_out': False, '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 0, 'relation': 'eq'}, 'max_score': None, 'hits': []}} 我需要检查结果['hits']['total']['value']是否为0或!0 本地代码运行良好,如下

结果如下

result = {'took': 5, 'timed_out': False, '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 0, 'relation': 'eq'}, 'max_score': None, 'hits': []}}
我需要检查
结果['hits']['total']['value']
是否为
0
!0

本地代码运行良好,如下所示

if result['hits']['total']['value']!=0:
    print (result)
elif result['hits']['total']['value']==0
    print ('no values to print ')
在Lambda中,它的抛出语法错误

def lambda_handler(event, context):
    result = {'took': 5, 'timed_out': False, '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 0, 'relation': 'eq'}, 'max_score': None, 'hits': []}}
    print (result)
    if result['hits']['total']['value'] != 0:
        return {
            'body':result
               }
    elif result['hits']['total']['value']=0
        return{
            'body': json.dumps('No values found!')
        }

应该使用以下语法,您的elif语句结尾缺少
,必须始终包含此语法

def lambda_handler(event, context):
    result = {'took': 5, 'timed_out': False, '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 0, 'relation': 'eq'}, 'max_score': None, 'hits': []}}
    print (result)
    if result['hits']['total']['value'] != 0:
        return {
            'body':result
               }
    elif result['hits']['total']['value'] == 0:
        return{
            'body': json.dumps('No values found!')
        }

elif result['hits']['total']['value']==0
?@Rakesh我已经试过了?哪一行是语法错误?你忘了在句子
elif result['hits']['total']['value']==0
中加上
,我正在投票结束这个问题,因为它是由打字错误引起的。