Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

what is lambda in OpenERP? [Closed]

By
priyankahdp
on 3/14/13, 8:29 AM 6,362 views

The Question has been closed

by
priyankahdp
on 04/20/2013 03:21:14
_defaults = {
    'user_id': lambda self, cr, uid, context: uid,

need to clarify above code segment..? is it work as a function.? if yes self, cr, uid, context: uid are act as a parameters of that method.i'm confused with that phase

please help me

5

Parth Gajjar

--Parth Gajjar--
1484
| 3 3 5
Ahmadabad, India
--Parth Gajjar--
Parth Gajjar
On 3/14/13, 8:42 AM

Lambda is not openerp object it is from python.

Click Here: Know about lambda

And yes is work like anonymous functions

plz check above comment

priyankahdp
on 3/14/13, 8:58 AM

def _function(self,cr,uid): return uid

is simple function.Above link has example like this

`def make_incrementor (n): return lambda x: x + n
f = make_incrementor(2)
g = make_incrementor(6)
print f(42), g(42)`

Output is : 44 48

Parth Gajjar
on 3/14/13, 9:38 AM
3

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 3/14/13, 8:44 AM

lambda is not specific to OpenERP. It is a statement used by Python to declare functions. Here is a good tutorial about it: http://pythonconquerstheuniverse.wordpress.com/2011/08/29/lambda_tutorial/

In you case lambda is used to reference the field uid from the function arguments.

You can see in openerp/osv/orm.py how the default function is called:

default = self._defaults[k](self, cr, SUPERUSER_ID, context)

when we wrote above code under the function standard def _function(self,cr,uid): return uid

is this correct.? if not please mention correct one

priyankahdp
on 3/14/13, 8:56 AM

I am not sure what you would like to do, but lambda is used to "extract" the parameters from the call. I have updated my answer with a call of the default-function.

Andreas Brueckl
on 3/14/13, 9:03 AM

Can we save the result and get it printed since i saw somewhere that lambda cannot return any value!

evon_dun
on 8/20/13, 5:21 AM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 3/14/13, 8:29 AM
Seen: 6362 times
Last updated: 3/16/15, 8:10 AM