python - 转义保留关键字 Python

标签 python python-3.x netsuite zeep suitetalk

<分区>

我正在使用 ZEEP 连接到 NetSuite。创建发票时我需要传递给 NS 的参数之一是“类”。如果我理解正确的话,下面这行没有编译的原因是因为“class”是一个保留关键字。

invoice = invoiceType(
    customFieldList = customFieldList,
    entity = entityRecord,
    subsidiary = subRecord,
    department = departmentRecord,
    location = locationRecord,
    class = classRecord
)

我没有将最后一个参数从“类”更改为“类”或其他内容的选项,因为这是 NetSuite 期望调用的参数。我可以在 python 中使用任何替代方法吗?有没有办法在将其作为参数传递时对其进行转义?

最佳答案

您需要使用 **{...} 语法来传递名称为保留字的关键字参数。

invoice = invoiceType(
              customFieldList=customFieldList, 
              entity=entityRecord,
              subsidiary=subRecord,
              department=departmentRecord,
              location=locationRecord,
              **{'class': classRecord}
           )

这样做是用一个名为 'class' 的键创建一个字典,然后将字典展开到一个参数中,这样您就不必指定文字 class 关键字.

关于python - 转义保留关键字 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54974442/

相关文章:

python - PyCharm - venv 没有被激活

python - 如何解析多个xml文件并将属性传递给csv?

javascript - NetSuite reSTLet 写性能差

php - 通过 PHP7.0-FPM 为 ODBC 连接更新系统范围的 LD_LIBRARY_PATH

python - Seaborn 的 relplot : Is there a way to assign a specific color to all lines and another color to another single line when using the hue argument?

Python sqlite - 在 execute() 方法中引用用法

python - Pandas :将每一列聚合成逗号分隔的列表,不重复

python - 具有大量条件的 pandas read_hdf

python - 基于多个列值输出多个文件 pandas python

html - NetSuite 高级 PDF 模板 CSS 和 HTML 在添加额外的表格行时忽略高度并弄乱布局