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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:21:20+00:00 2026-06-14T13:21:20+00:00

I’m working on a wrapper script written in Python. The wrapper is supposed to

  • 0

I’m working on a wrapper script written in Python. The wrapper is supposed to choose another Python script based on the system state and execute it (using the absolute path). There is no need to return to the parent script.

It should be noted that I have no control over the scripts being run. They can use __name__ checks, access sys.argv and it should all behave like if the script was run directly.

Right now, I’m using os.execl():

import os, sys

# ...

os.execl(sys.executable, sys.executable, new_script, *sys.argv[1:])

But I can count at least three issues with that:

  1. Any options passed to the Python interpreter are not preserved (e.g. python -v wrapper stops being verbose on re-exec);
  2. The Python interpreter is re-executed unnecessarily (with PyPy it adds 0,7s on my system);
  3. It relies on sys.executable being useful, and the docs say that:

    If Python is unable to retrieve the real path to its executable, sys.executable will be an empty string or None.

I’m wondering what replacement I should use for the os.execl call to solve all the issues. So far, I can tell that:

  1. execfile() would probably work but it was removed in Python3 and re-implementing it by hand AFAICS is ugly (because of the encoding issues). I’m not sure what other implications can execfile() have;
  2. imp.load_module() would probably work but it’s a bit hacky and was deprecated in Python3.3. It probably can suffer Python3 encoding issues as well.

Which solution do you suggest I use?


Edit: I’d forget. The solution has to work with Python 2.5+, PyPy and Jython 2.5+.

  • 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-14T13:21:21+00:00Added an answer on June 14, 2026 at 1:21 pm

    I would just use execfile() instead of imp.load_module(). Although control will be returned to the executive script, one big advantage is that, quoting the docs:

    It is different from the import statement in that it does not use the
    module administration — it reads the file unconditionally and does not
    create a new module.

    This means the script file can be anywhere, can have any (or no) file extension, and resources aren’t wasted doing module-import related tasks.

    Doing so automatically accomplishes or avoids the things you desire:

    1. interpreter options will be preserved
    2. interpreter will not be re-executed unnecessarily
    3. it does not rely on the value of sys.executable
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.