Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.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
Python 仅当长度大于零时传递参数_Python_Amazon Dynamodb_Boto3 - Fatal编程技术网

Python 仅当长度大于零时传递参数

Python 仅当长度大于零时传递参数,python,amazon-dynamodb,boto3,Python,Amazon Dynamodb,Boto3,我在dynamodb的query命令上调用一个方法,并且属性filtereexpression是可选的,或者它接受一个非空字符串 只有当filter>的长度为0时,我才能将filtereexpression作为参数传递吗 def select(filter='') response = self.dynamodbConnection.query( FilterExpression=filter # Other arguments here ) 或

我在dynamodb的
query
命令上调用一个方法,并且属性
filtereexpression
是可选的,或者它接受一个非空字符串

只有当
filter>的长度为0
时,我才能将
filtereexpression
作为参数传递吗

def select(filter='')
    response = self.dynamodbConnection.query(
        FilterExpression=filter
        # Other arguments here
    )


第二种方法就是我想要的!
def select(filter=''):
    if len(filter) > 0:
        response = self.dynamodbConnection.query(
            FilterExpression=filter
        )
    else:
        response = self.dynamodbConnection.query(# Other arguments here)
def select(filter=''):
    args = {}
    if len(filter) > 0:
        args['filter'] = filter
    response = self.dynamodbConnection.query(**args)