Cool Breeze
Cool Breeze

Reputation: 910

How to concatenate variables like this in python

eg. correct sample -

f.write("\t" +connection_name+ "\t =" + qs.connection_name + "\n")

what I'm trying to do -

f.write("\t" +current+ "\t=" +qs.current+ "\n")

//here current = 'connection_name'

How to concatenate in this kind - qs.current so that it prints as qs.connection_name's value

Upvotes: 2

Views: 49

Answers (1)

Cory Kramer
Cory Kramer

Reputation: 117856

You can use getattr

getattr(qs, current)

So in the context of your code

f.write("\t" + current + "\t=" + getattr(qs, current) + "\n")

Upvotes: 2

Related Questions