<p>I have a model class:</p>

<pre><code>class Person(db.Model):
  first_name = db.StringProperty(required=True)
  last_name = db.StringProperty(required=True)
</code></pre>

<p>I have an instance of this class in <code>p</code>, and string <code>s</code> contains the value <code>'first_name'</code>. I would like to do something like:</p>

<pre><code>print p[s]
</code></pre>

<p>and </p>

<pre><code>p[s] = new_value
</code></pre>

<p>Both of which result in a <code>TypeError</code>.</p>

<p>Does anybody know how I can achieve what I would like?</p>

```
```
getattr(p, s)
setattr(p, s, new_value)
```
```