Python 仅当长度大于零时传递参数
我在dynamodb的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 ) 或
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)