1

Python (3.7)

I am trying to write a simple function that returns metadata from a Salesforce object (table), where table name is an argument. in the example below Booking__c is an object(table) name and it returns collections.OrderedDict as expected.

from simple_salesforce import Salesforce
sf=Salesforce(username,password,organizationId)

table_info=sf.Booking__c.describe()

However, I need to write a function so I can reuse it for multiple tables. I tried exec() but it returns NoneType

def all_columns(table):
    c = exec("sf.table.describe()")
    return c

I know that exec() is not recommended to use, so would appreciate a piece of advice if there is a proper way to achieve this, or at least help with exec.

0

1 Answer 1

2

I think you'd need eval here instead if you need a return value, as I believe exec is purely for executing side effects.

There's no need for either though. You can access an attribute of an object by name using getattr:

c = getattr(sf, table).describe()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.