If you're using Python 2.7, you can use a dictionary comprehension:
db.Account_Master.insert(**{f: 'somevalue' for f in db.MyTable.fields})
otherwise, a generator expression passed to dict:
db.Account_Master.insert(**dict((f, 'somevalue') for f in db.MyTable.fields
))
Anthony
On Sunday, April 29, 2012 3:08:44 AM UTC-4, rahulserver wrote:
>
> The insert function in web2py expects db.tablename.insert(...) with column
> name and value pairs. What if the table has lengthy field names and i wish
> to insert in the table by iterating through all the fields.
> I tried:
>
> for field in db[db.MyTable]:
> nme='\''+field.name+'\''
> db.Account_Master.insert(nme='somevalue')
>
> It is giving me error as:
> <type 'exceptions.SyntaxError'> Field nme does not belong to the table
>
> When i try field.name instead of nme, editor does not let me save and
> gives error as:
>
> keyword can't be an expression
>
>