Link to home
Start Free TrialLog in
Avatar of srbarker8
srbarker8Flag for Canada

asked on

Python CherryPy SQLAlchemy class - how to loop through form vars and assign to dat aobject

Hi there,

I am using CherryPy and SQLALchemy and I am trying to put some code together to loop through the posted form vars and assign their values to my data object.  There are a lot of cases where I want to do this and the data records have a LOT of fields.

So, if the class I am trying to assign the values to is User with Last_Name and First_Name columns, for example.

I can loop through the kwargs and get the form vars.  The posted form-vars names/id's correspond with the column names on my User object.

But I don't know how to code an assignment as an expression

This_Object = User()     ... gives me my data class/object

.. then I loop through the parms ...

for lcParm in kwargs:
 lcVal = kwargs.get(lcParm,'')

..so, I can loop through and pick up the values, but how do I code the assignment of the value to the data object field?

The name is in lcParm (eg; Last_Name) .. but how do I code This_Object.lcParm = lcVal

Please help!

Thx, Scott
ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial