0

In PHP we can refer to an attribute of an object dynamically like this $obj->{$field}.

How can the same thing be achieved in python?

1

1 Answer 1

0

To get the value of an attribute dynamically, you can use getattr(obj, field_name).

To set the value dynamically, you can use setattr(obj, field_name, new_value).

To test whether the attribute exists, like isset in PHP, you can use hasattr(obj, field_name).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.