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+.