That's just Python. When the lambda's are called, they get the value of 
name from the scope in which they were defined, so all the lambdas will use 
the last value of name, which is the last month. Instead, you should pass 
in name as an argument to each lambda, which will put it in the scope of 
the lambda.

Anthony

On Monday, December 23, 2013 5:53:34 PM UTC-5, P T wrote:
>
> Thank you Anthony, that worked like a charm. Is this technique I should 
> learn in Python or Web2Py?
>
> PT
>
> On Monday, December 23, 2013 3:17:56 PM UTC-6, Anthony wrote:
>>
>> Try:
>>
>> lambda value, row, name=name: ...
>>
>> Anthony
>>
>> On Monday, December 23, 2013 11:38:08 AM UTC-5, P T wrote:
>>>
>>> I am using the following for "represent" fields in the table:
>>> *{Field(name, 'integer', default=0, represent = lambda value, row: 
>>> DIV(value 
>>> if value else '-',_class='month', _id=str(row.id) +'.'+name)) for name 
>>> in fields}
>>>
>>>
>>> The intention is to use jeditable for which I need a class and an id for 
>>> each td element. But, all the td elements in a row are getting the same 
>>> month (specifically last month in the list) in the id, e.g. each td element 
>>> id is 72.Dec_2014. I am expecting 72.Jan_2014, 72.Feb_2014, 
>>> 72.Mar_2014,..., 72.Dec_2014. How should do I modify definition of 
>>> represent? 
>>>  
>>>
>>> Here is complete definition of tables:
>>>
>>> fields=[] 
>>> for row in  db(db.months).select(): 
>>>     fields.append(row.effort_month.strftime('%b_%Y'))
>>>
>>>
>>> db.define_table("monthly_projections", 
>>>                 Field('employee', 'reference auth_user', default=auth.
>>> user_id, writable=False), 
>>>                 Field('costcode', 'reference costcodes', notnull=True),
>>>                 *{Field(name, 'integer', default=0, represent = lambdavalue
>>> , row: DIV(value if value else '-',_class='month', _id=str(row.id) +'.'+
>>> name)) for name in fields}
>>>                 )
>>>
>>>
>>> Thanks for your help,
>>>
>>> PT 
>>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to