Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8489547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:51:34+00:00 2026-06-10T21:51:34+00:00

While going developing OpenERP, I found the following piece of code ‘app_date’: lambda *a:

  • 0

While going developing OpenERP, I found the following piece of code

'app_date': lambda *a: time.strftime('%Y-%m-%d')

I know what lambda is.My question is why use lambda?Why not just

'app_date': time.strftime('%Y-%m-%d')

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:51:36+00:00Added an answer on June 10, 2026 at 9:51 pm

    'app_date': time.strftime('%Y-%m-%d') will evaluate the time.strftime immediately. By wrapping it in a lambda, its execution is deferred until later (the time when you call the lambda). Roughly speaking, the difference is between “the time when I defined this” and “the time when I am using this”. Look:

    >>> d = {'a': time.time(), 'b': lambda: time.time()}
    >>> d['a'], d['b']()
    (1346913545.049, 1346913552.409)
    >>> d['a'], d['b']()
    (1346913545.049, 1346913554.518)
    >>> d['a'], d['b']()
    (1346913545.049, 1346913566.08)
    

    I allowed some time to elapse in between each d['a'], d['b'](). Note that d['a'] is always the same: it is the time when I defined d. d['b'] is a function. d['b']() (with parentheses) calls the function, which evaluates the time anew on each call, so it is different at each usage.

    Also, this is nothing special about lambda. Lambdas are just functions like any other. I could do the same with:

    def func():
        return time.time()
    d = {'a': time.time(), 'b': func}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While going through Effective C++ (by Scott Meyers), I came across the following code
While going through the syslog file, I found a message like shutdown via gdm
Yesterday while going through this question, I found a curious case of passing and
I've moved to a new project team and while going over the codebase, found
I've been working on developing an app for a while, and everything was going
I'm developing a software, which is going to provide in-deep information about url's. While
While going through SWig generated wrappers, I find that the PInvokes don't have any
While going through some tutorials, I have encountered lines such as this: ((IDisposable)foo).Dispose(); Ignore
While going through many resources on multithreaded programming, reference to volatile specifier usually comes
While going through the book Scala for the Impatient , I came across this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.