点表示法和使用字符串访问模块函数

huangapple go评论52阅读模式
英文:

dot notation and accessing module functions using strings

问题

对于你的代码问题,你可以尝试使用以下解决方法:

objectName = "Account"
sf.bulk[objectName].upsert(dataToSalesforce, externalIdField, batch_size=10000)

这个修改应该能够解决你的问题。它允许你使用变量 objectName 作为对象的名称来执行 upsert 操作,而不会将其解释为字符串 "objectName"。这样,你可以动态地更改 objectName 的值以适应不同的对象。

英文:

pretty new to python, so i tried googling around for answers but i was probably googling the wrong terminology.

So here's my problem

i have this

objectName ="Account"

sf.bulk.objectName.upsert(dataToSalesforce,externalIdField, batch_size=10000)

The above command should send an upsert request for salesforce upserting on the account object, but it gives me the error {'exceptionCode': 'InvalidJob', 'exceptionMessage': 'Unable to find object: objectName'}

the problem is it tried to query the object objectName and not Account.

Everything works fine when i use: sf.bulk.Account.upsert(dataToSalesforce,externalIdField, batch_size=10000) but in the current use case the object being upserted to may change.

答案1

得分: 0

当查看错误时,我注意到它使用了术语“attribute”,并在使用该术语进行谷歌搜索时,我发现我可以这样做

getattr(sf.bulk, objectName).upsert(dataToSalesforce, externalIdField, batch_size=10000, use_serial=True)

这解决了问题。

英文:

When looking at errors I noticed it used the term attribute, and googling using that term I found I could do this

getattr(sf.bulk, objectName).upsert(dataToSalesforce, externalIdField,batch_size=10000, use_serial=True)

that solves the issue.

huangapple
  • 本文由 发表于 2023年2月16日 04:45:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465266.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定