python-3.x - 在一个函数调用中有多个参数,但在另一个函数调用中没有
问题描述
我正在研究机器人框架,我的基本方法之一是用 python 编写的,用于构建具有 n 列和多个 where 条件的 SQL 查询。该功能看起来像,
from pypika import Query, Table, Field
def get_query_with_filter_conditions(table_name, *column, **where):
table_name_with_no_lock = table_name + ' with (nolock)'
table = Table(table_name_with_no_lock)
where_condition = get_where_condition(**where)
sql_query = Query.from_(table).select(
*column
).where(
Field(where_condition)
)
return str(sql_query).replace('"', '')
我在我的机器人关键字中将此方法称为:
Get Query With Filter Conditions ${tableName} ${column} &{tableFilter}
这个函数在另外两个关键字中被调用。一方面,它工作正常。对于另一个它不断抛出错误
关键字“queryBuilderUtility.Get Query With Filter Conditions”得到了参数“table_name”的多个值。
工作正常的关键字如下所示:
Verify the ${element} in ${grid} is fetched from ${column} column in ${tableName} table from DB
[Documentation] Verifies Monetary values in the View Sale Grid
${feature}= Get Variable Value ${FEATURE_NAME}
${filterValue}= Get Variable value ${FILTER_VALUE}
${queryFilter}= Get the Test Data valid ${filterValue} ${feature}
&{tableFilter}= Create Dictionary
Set To Dictionary ${tableFilter} ${filterValue}=${queryFilter}
Set To Dictionary ${tableFilter} form_of_payment_type=${element}
${tableName}= Catenate SEPARATOR=. SmartPRASales ${tableName}
${query}= Get query with Filter Conditions ${tableName} ${column} &{tableFilter}
Log ${query}
@{queryResult}= CommonPage.Get a Column values from DB ${query}
总是抛出错误的函数如下所示:
Verify ${element} drop down contains all values from ${column} column in ${tableName} table
[Documentation] To verify the drop down has all values from DB
${feature}= Get Variable Value ${FEATURE_NAME}
${filterElement}= Run Keyword If '${element}'=='batch_type' Set Variable transaction_type
... ELSE IF '${element}'=='channel' Set Variable agency_type
... ELSE Set Variable ${element}
&{tableFilter}= Create Dictionary
Set To Dictionary ${tableFilter} table_name=GENERAL
Set To Dictionary ${tableFilter} column_name=${filterElement}
Set To Dictionary ${tableFilter} client_id=QR
Log ${tableFilter}
Log ${tableName}
Log ${column}
${tableName}= Catenate SEPARATOR=. SmartPRAMaster ${tableName}
${query}= Get Query With Filter Conditions ${tableName} ${column} &{tableFilter}
Log ${query}
@{expectedvalues}= CommonPage.Get a Column values from DB ${query}
有人可以帮助我纠正我在这里做的错误吗?
解决方案
问题是由于字典中的键值对造成的。字典中的关键之一
&{tableFilter}= Create Dictionary
Set To Dictionary ${tableFilter} table_name=GENERAL
与中的论点之一相同
def get_query_with_filter_conditions(table_name, *column, **where):
将 get_query_with_filter_conditions 函数中的参数从 table_name 更改为 p_table_name 并且它起作用了。由于该函数采用可以指定为命名参数的位置参数,python 将我传递的 table_name 参数与字典中键 table_name 的参数混淆了。
推荐阅读
- python - 查找每个单独列表元素的所有组合
- javascript - 在 Lambda 中的 node8.10 中获取 API 调用导致 Promise
和未定义 - html - 除了angularjs中的几个链接外,如何在点击时隐藏div
- c# - 可以将 ID(字符串)列表传递给 MongoDB 的删除方法吗?
- autohotkey - 试图在我的键盘上识别 Fn + V
- java - 如何以最低要求运行 Spring Boot 应用程序?
- javascript - 让导航栏 onclick/href 在圆形元素上执行动画然后加载新页面 - 如何?
- javascript - 单击顶部的链接时会调用 onclick 函数
- javascript - 如何附加一个`` 选择之前/之后 `
`给定clientHeight的元素?
- macos - 使用命令行参数将软件部署到 macOS 端点