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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:24:07+00:00 2026-05-25T18:24:07+00:00

I have an existing python application (limited deployment) that requires the ability to run

  • 0

I have an existing python application (limited deployment) that requires the ability to run batches/macros (ie do foo 3 times, change x, do y). Currently I have this implemented as exec running through a text file which contains simple python code to do all the required batching.

However exec is messy (ie security issues) and there are also some cases where it doesn’t act exactly the same as actually having the same code in your file. How can I get around using exec? I don’t want to write my own mini-macro language, and users need to use multiple different macros per session, so I can’t setup it such that the macro is a python file that calls the software and then runs itself or something similar.

Is there a cleaner/better way to do this?

Pseudocode: In the software it has something like:
-when a macro gets called

for line in macrofile:
   exec line

and the macrofiles are python, ie something like:

property_of_software_obj = "some str"
software_function(some args)

etc.

  • 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-25T18:24:08+00:00Added an answer on May 25, 2026 at 6:24 pm

    Have you considered using a serialized data format like JSON? It’s lightweight, can easily translate to Python dictionaries, and all the cool kids are using it.

    You could construct the data in a way that is meaningful, but doesn’t require containing actual code. You could then read in that construct, grab the parts you want, and then pass it to a function or class.

    Edit: Added a pass at a cheesy example of a possible JSON spec.

    Your JSON:

    {
        "macros": [
            {
                "function": "foo_func", 
                "args": {
                    "x": "y", 
                    "bar": null
                }, 
                "name": "foo", 
                "iterations": 3
            }, 
            {
                "function": "bar_func", 
                "args": {
                    "x": "y", 
                    "bar": null
                }, 
                "name": "bar", 
                "iterations": 1
            }
        ]
    }
    

    Then you parse it with Python’s json lib:

    import json
    
    # Get JSON data from elsewhere and parse it
    macros = json.loads(json_data)
    
    # Do something with the macros
    for macro in macros:
        run_macro(macro) # For example
    

    And the resulting Python data is almost identical syntactically to JSON aside from some of the keywords like True, False, None (true, false, null in JSON).

    {
        'macros': [
            {
                'args': 
                {
                    'bar': None, 
                    'x': 'y'
                },
                 'function': 'foo_func',
                 'iterations': 3,
                 'name': 'foo'
            },
            {
                'args': 
                {
                    'bar': None, 
                    'x': 'y'
                },
                 'function': 'bar_func',
                 'iterations': 1,
                 'name': 'bar'
            }
        ]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing python module with a dash in its name, foo-bar.py Changing
For whatever reason, I have a lot of clients that have existing data that's
We have an existing WCF service that makes use of wsDualHttpBinding to enable callbacks
I have an existing website that uses the same code base, but is deployed
I have an existing library (JPhysX) that is a Java wrapper for a native
I have an existing web app that allows users to rate items based on
I have a small lightweight application that is used as part of a larger
We have an existing java-based heavyweight project that needed an interactive script interpreter. After
I have an existing python script and I want to wrap it in a
I have an already existing app with alot of database entries . class Foo(models.Model):

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.