Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

data.name='Some Name'
col1='name'

data.col1  ???

how to access data using only var col1,
like data.col1 or some thing
Simple the variable name is stored in another variable, actually from a django request.

share|improve this question
Is this what you want? They mention eval as well. You could also rewrite the response so that it returns some status code instead. – Keyser 20 hours ago
@MartijnPieters how the ,will you reach on that possible duplicate by searching with 'variable inside another variable for python'. you have to know that thing after . is an attribute to search like that. moderators. – Abhishek Lal 14 hours ago
That is what duplicates are for; if you search next time, you will find this one, which automatically redirects you to the other one. Don't worry about it. – Martijn Pieters 14 hours ago

marked as duplicate by Martijn Pieters, Mark Rotteveel, Haidro, Stony, Ashwin Mukhija 11 hours ago

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 2 down vote accepted

Use getattr:

getattr(data,col1)
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.