0

How to call for the object parameter if the parameter is a variable string. In this case is variable beacuse it is the header in a database column_header = "variable string"

lambda rec: (rec.column_header) another case item.column_header = new_value

1
  • What do you mean by "object parameter"? Commented Nov 19, 2020 at 18:05

1 Answer 1

4
  • To read a property from a string as name use getattr()

    getattr(obj, name)
    
  • To set a property from a string as name use setattr()

    setattr(obj, name, value)
    

In your case it'd mean

  • Get

    column_header = "variable string"
    lambda rec: getattr(rec, column_header)
    
  • Set

    column_header = "variable string"
    setattr(item, column_header, new_value)
    
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.