user2661518
user2661518

Reputation: 2755

Get argument from different method

I am passing object as follows

test = TestClass(parameter1=''first_name', parameter2='last_name')

And in another method I am accessing parameter1 as

print test.parameter1

I get output as first_name

But if I have variable which contains value assigned to parameter1. Can I use variable to get value?

var = 'parameter1'

What's the right way to perform like test.var? For this I get attribution error.

What's the programming word for 'parameter1', is it options, argument options?

Upvotes: 0

Views: 33

Answers (1)

VadimK
VadimK

Reputation: 615

Guess you need getattr function:

getattr(test, var)

Upvotes: 2

Related Questions