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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:46:44+00:00 2026-05-29T15:46:44+00:00

I was reading some questions about not to use exec or eval in python

  • 0

I was reading some questions about not to use exec or eval in python code.

I currently have a python web program based on pyramid and it takes some variables from a form and calls a function. All the argument of this function or optional, thus more or less what I do is

command = 'function_to_be_called ('

if optional_variable_in_form in request.params :
    command += 'optional_variable=optional_variable_in_form'

command += ')'

i = eval (command)

I am trying to enhance my application and I am trying to replace eval with something else. I found this answer, where the author suggests to pass a dictionary by reference instead of using my solution.

So my questions are:

  1. do you think it’s a good way to go?
  2. can I always pass a dictionary as proposed by the author to any function?
  3. I find quite ofter the **, but I don’t understand well what it does. Can you give me a hint about it or suggest a good page where I can study about it?
  • 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-29T15:46:46+00:00Added an answer on May 29, 2026 at 3:46 pm

    You can just do:

    function_to_be_called(**option_dict)
    

    The old way to do this was with the apply function, but that has now been deprecated for the *args, and **keywords syntax.

    This is actually really cool, since it means you can have a function and a tuple of arguments and call the function, so:

    def polly(cracker, wants):
        if wants:
           print 'polly wants a', cracker
    f = polly
    t = ('cracker', True)
    

    These are now all equivalent:

    polly('cracker', True)
    polly(*('cracker', True))
    polly(*t)
    f('cracker', True)
    f(*t)
    

    Now expand that for keyword arguments – but look up a real tutorial. But as @Duncan points out, you can do this:

    polly(**{cracker: 'cracker', wants: True})
    d = {cracker: 'biscuit', wants: True}
    polly(**d)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about how to use Dispose() and destructors. Reading some articles
I've been doing some reading into designing template code have a question about it.
Reading some questions here on SO about conversion operators and constructors got me thinking
I came across couple of questions about OCL expressions. After reading some university slides
I came across this class while reading a C# book and have some questions.
I've been reading a lot of stackoverflow questions about how to use the breadth-first
I've been doing some simple web programming using python, and I have a basic
I have been reading other questions and answers around this but I am not
Reading through some of the questions here, the general concensus seems to be that
After reading a couple of answers and comments on some SQL questions here, and

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.