Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape Reserved Keywords Python [duplicate]

I am using ZEEP to connect to NetSuite. One of the parameters that I need to pass to NS when creating the invoice is 'class'. If I understand correctly, the reason the following line does not compile is because 'class' is a reserved keyword.

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

I don't have the option to change the last parameter from say 'class' to 'Class' or something else, since this is what NetSuite expects the parameter to be called. Are there any alternatives that I can use in python? Is there a way to escape this while passing it as a parameter?

like image 960
tkansara Avatar asked Aug 22 '26 19:08

tkansara


1 Answers

You'll need to use the **{...} syntax to pass a keyword argument whose name is a reserved word.

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

What this is doing is creating a dictionary with a key called 'class' and then unrolling the dictionary into an argument so you never have to specify the literal class keyword.

like image 157
chepner Avatar answered Aug 25 '26 07:08

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!