Try recnr = db.xx.insert(**x)
 
The **x will expand your dictionary into a set of keyword arguments.
 
Anthony

 
On Thursday, April 14, 2011 9:40:47 AM UTC-4, spyker wrote:

> I want to insert a dictionary into a table and work the resulting id.
>
> The following illustrates my problem:
>
> db.define_table('xx',
>          Field('a'),
>          Field('b'))
>
> x = {}
>
> x['a'] = 'abcd'
> x['b'] = 'dbcs'
>
> db.xx[0] = x #  Success but how do I get the id?
>
> This should be equivalent to db.xx.insert(x) as I understand the book but
>
> recnr = db.xx.insert(x)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
>
> /home/js/web2py/<ipython console> in <module>()
>
> TypeError: insert() takes exactly 1 argument (2 given)
>
> So how do I insert a dictionary without having to type out all the fields 
> individually  like this;
>
> auid = db.isi_authors.insert (name = name,
>                                       surname = surname,
>                                       firstname = firstname,
>                                       address = address)
>
> Regards
>
> Johann
> -- 
>  May grace and peace be yours in abundance through the full knowledge of 
> God and of Jesus our Lord!  His divine power has given us everything we need 
> for life and godliness through the full knowledge of the one who called us 
> by his own glory and excellence. 
>                                                     2 Pet. 1:2b,3a
>
>

Reply via email to