abyss.7 abyss.7 - 5 months ago 18
Python Question

How to execute python script with arguments from the "frozen" Python binary?

I have built a python binary with embedded frozen modules and some main script. Let's call the binary

pyemb
.

I want to use some of frozen modules from other python scripts - it seems that the best solution is to provide interface from
pyemb
, like:

pyemb python "somescript.py --arg1 --arg2 arg3"


But how can I implement the command
python
within my python script itself?

There are
exec
and
execfile
Python functions, but they don't work with arguments and other command-line stuff.

Answer

Something simple like this should work:

if sys.argv[1] == 'python':
    sys.argv.pop(1)
    import runpy
    runpy.run_path(sys.argv[1], run_name="__main__")

The module runpy comes very handy.

Comments