title: Is there a way to pass a class/instance attribute name as a variable?
body: <p>I am using a class to model and manage a database table, but due to the nature of the data I am usually only updating a single column (attribute) at a time. Is there a way to pass which column (attribute) to update?</p>
  <p>Example: Let's say I'm making a log of who has last used an access point.</p>
  <pre><code>Base = declarative_base()
  class Log(Base):
     __tablename__ = &quot;log&quot;
     id = Column(Integer, primary_key=True)
     access_point = Column(Integer, unique=True)
     admin = Column(String)
     staff = Column(String)
     consult = Column(String)
     visitor = Column(String)
  </code></pre>
  <p>I want a way to pass which user_type (admin/staff/consult/visitor) to an aux function to handle the insertion/updating, including the creation of new access_points, something like:</p>
  <pre><code>def db_update(a_p, user_info, user_type):
     q = session.query(Log).filter(Log.access_point == a_p)
     if session.query(q.exists()).scalar():
          stmt = update(Log).where(Log.access_point == a_p).values(user_type=user_info)
          session.execute(stmt)
     else:
          new_point = Log(access_point = a_p, user_type = user_info)
          session.add(new_point)
  </code></pre>
  <p>Is there a way of doing this other than just passing a comparator of some sort to pick the user_type (i.e. &quot;if user_type == 1, update admin&quot; sort of thing)?</p>