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

  • Home
  • SEARCH
  • 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 9272321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:50:52+00:00 2026-06-18T15:50:52+00:00

I have a wrapper python script which repeatedly calls another python script via os.system

  • 0

I have a wrapper python script which repeatedly calls another python script via os.system. This works well enough, but there is quite a performance hit invoking the sub-shell and importing the modules again and again. How might I transform this to something more elegant and performant?

counter = 0
for thing in list_of_stuff:
    os.system("python inner_script.py %s result_%s" % (thing, counter)
    counter += 1

I would prefer to do this all in the wrapper, but can modify inner-script.py if that’s the only or best way.

If it’s relevant, the environment is Python 2.7 on Windows.

edit: I don’t just import inner_script because it doesn’t understand the command line parameters:

import inner_script    
counter = 0
for thing in ['TR2','TR5']:
    inner_script('%s result_%s' % (thing, counter))
counter += 1

result:

C:\> python xx-wrapper.py

inner_script [input features] [output workspace]

which is the usage message returned by inner_script.py:

if len(sys.argv) < 3:
    print usage
    exit()

in_features = sys.argv[1]
out_folder  = sys.argv[2]

main(in_features, out_folder)
  • 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-18T15:50:53+00:00Added an answer on June 18, 2026 at 3:50 pm

    In inner-script.py create a class around the task that the script does.

    for thing in list_of_stuff:
        x = __import__('inner-script')
        x.className(thing, counter)
    

    This should be efficient enough.


    Or, if you can’t/wont modify the inner-script.py, here’s a way to call it from within python and pass variables as local() or global() variables which the script can read from.. just as if you passed the params upon execution in your example:

    x = __import__('inner-script', globals(), (thing, counter), [], -1)
    

    Then whatever stuff you want to be, more info can be found here

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

Sidebar

Related Questions

Scenario 1: I have one wrapper Perl script which uses another Perl module and
I am really stumped on this one. I have a simple python wrapper which
I have a python script that serves as an additional wrapper around tummy's memcached
I have this problem: System A runs Ubuntu and needs Python 2.6 for a
I have a python module/script which does a few of these At various nested
Greetings. I have written a little python script that calls MySQL in a subprocess.
I have managed to set up Cassandra + Thrift and the Python wrapper for
In my project, I have a wrapper class named PlayerCluster.java , which loads the
I have a python script that creates and starts 3 threads, and then goes
I have a working python wrapper for C++ code (as suggested here Calling C/C++

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.