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 220925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:59:06+00:00 2026-05-11T18:59:06+00:00

These weekend I’ve been tearing down to pieces Michele Simionato’s decorator module , that

  • 0

These weekend I’ve been tearing down to pieces Michele Simionato’s decorator module, that builds signature-preserving decorators. At the heart of it all there is a dynamically generated function, which works something similar to this…

src = """def function(a,b,c) :\n    return _caller_(a,b,c)\n"""
evaldict = {'_caller_' : _caller_}
code = compile(src, '<string>', 'single')
exec code in evaldict
new_func = evaldict[function]

I have found, fooling around with this code, that the compile step can be completely avoided and go for a single:

exec src in evaldict

Now, I’m sure there is a good reason for that additional step, but I haven’t been able to find what the difference between both approaches is. Performance?

And since I’m asking, could something similar, i.e. define a new function and get a handle to it, be achieved with eval? I tried, but couldn’t get that to work…

  • 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-05-11T18:59:06+00:00Added an answer on May 11, 2026 at 6:59 pm

    There are a few differences that I see. Firstly, compile has slightly better semantics in the face of syntax errors than exec. I suspect that the real reason is that the definition of compile is very explicit with respect to the handling of new line characters where exec is a little less precise.

    I was curious as to why compile and exec where being used in lieu of inner functions. I didn’t know that compile/exec lets you control what globals are available. Very interesting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

These are the memory leaks that I am getting: http://twitter.com/AWEHOFFICIAL/status/221182174811004929/photo/1/large
I got back from the weekend to discover that somebody ****ahem**** had missed a
The whole weekend, I've been learning how to use TinyMCE with ASP.NET MVC. I
Since the time has just changed the past weekend in places that use Daylight
I have been searching all weekend for the solution to this quandry and have
All this weekend I have been trying to setup a Rails 3.0.4 app in
I have been working at home on Gmail-Imap-Api on the weekend. It was working
I am doing some weekend coding exercises. I have a table that contains some
I've been frustrated by this for the entire weekend, plus a day or two,
These days I design some algorithms in python, but find first two greatest value

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.