In Python, when passing a list as a function argument, if you precede the list with a *, that is equivalent to entering each element of the list as a separate positional argument. When passing a dictionary as a function argument, if you precede the dictionary with a **, that is equivalent to entering each key and value in the dictionary as separate keyword arguments.
With SELECT, you can use *[list, of, items], but it turns out SELECT will also take a list without the * and automatically do the unpacking for you. Same with TR. Anthony On Monday, December 3, 2012 10:10:12 AM UTC-5, software.ted wrote: > > Hi Sorry for posting again ... more findings and more questions on the * > and **. > > I am getting same results when i use * or don't use it, what function > does the * and ** really do puzzling a bit... > > print SELECT([OPTION(s.name, _value=s.id) for s in > db(db.file_subject).select()]) am getting results > > <select> > <option value="1">Information Technology</option> > <option value="2">Correspondance</option> > </select> > > print SELECT(*[OPTION(s.name, _value=s.id) for s in > db(db.file_subject).select()]) > > <select> > <option value="1">Information Technology</option> > <option value="2">Correspondance</option> > </select> > > Quiet confusing. > > On 12/3/12, Teddy Nyambe <[email protected] <javascript:>> wrote: > > ...Hi Masimo, > > > > Its working when i remove the one asterisk (*)...with two its giving > > an error, my db is fine...look at the results: > > > > > > In [2] : print SELECT(*[OPTION(s.name, _value=s.id) for s in > > db(db.file_subject).select()]) > > <select><option value="1">Information Technology</option><option > > value="2">Correspondance</option></select> > > > > In [3] : print SELECT(**[OPTION(s.name, _value=s.id) for s in > > db(db.file_subject).select()]) > > Traceback (most recent call last): > > File "/home/www-data/web2py/gluon/contrib/shell.py", line 235, in run > > exec compiled in statement_module.__dict__ > > File "<string>", line 1, in <module> > > TypeError: type object argument after ** must be a mapping, not list > > > > > > Thanks for the help...what do the * and ** mean, in the book its not > > very clear I have failed to understand. > > > > Teddy L. > > > > On 12/3/12, Massimo Di Pierro <[email protected] <javascript:>> > wrote: > >> You do not need CAT > >> > >> SELECT(**[OPTION(s.name, _value=s.id) for s > >> in db(db.file_subject).select()]) > >> > >> yet I do not think this is the problem. Probably you have duplicated > >> options in database. > >> > >> > >> > >> On Monday, 3 December 2012 01:23:06 UTC-6, software.ted wrote: > >>> > >>> Hi, I have this unusual behavior of my code below, the options are > >>> being duplicated what could be the problem: > >>> > >>> #print SELECT(CAT([OPTION(s.name, _value=s.id) for s in > >>> db(db.file_subject).select()])) > >>> > >>> <select> > >>> <option value="<option value="1">Information > >>> Technology</option><option value="2">Correspondance</option>"> > >>> <option value="1">Information Technology</option> > >>> <option value="2">Correspondance</option></option> > >>> </select> > >>> > >>> ...Teddy L. > >>> > >> > >> -- > >> > >> > >> > >> > > > > > > -- > > > ....................................................................................... > > > > Teddy Lubasi Nyambe > > Opensource Zambia > > Lusaka, ZAMBIA > > > > Cell: +260 97 7760473 > > website: http://www.opensource.org.zm > > > > ~/ > > Human Knowledge belongs to the world! - AntiTrust > > > > Man is a tool-using animal. Without tools he is nothing, with tools he > > is all - Thomas Carlyle 1795-1881 > > > > /~ > > > > > -- > ....................................................................................... > > > Teddy Lubasi Nyambe > Opensource Zambia > Lusaka, ZAMBIA > > Cell: +260 97 7760473 > website: http://www.opensource.org.zm > > ~/ > Human Knowledge belongs to the world! - AntiTrust > > Man is a tool-using animal. Without tools he is nothing, with tools he > is all - Thomas Carlyle 1795-1881 > > /~ > --

