Odoo Help


what is lambda in OpenERP? [Closed]

on 3/14/13, 8:29 AM 9,207 views

The Question has been closed

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


Parth Gajjar

--Parth Gajjar--

| 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

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

Andreas Brueckl

--Andreas Brueckl--

| 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

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!

on 8/20/13, 5:21 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


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