Re: NOT handling command-line arguments

Sjoerd Mullender (Sjoerd.Mullender@cwi.nl)
Tue, 26 Jul 1994 12:38:50 +0200

> THIS IS A MESSAGE IN 'MIME' FORMAT.
> If you are reading this, your mail reader may not support MIME.
> Some parts of this message will be readable as plain text.

--mysteryboxofun
Content-Type: text/plain

On Tue, Jul 26 1994 Wilson GV wrote:

> I would like to be able to pass command-line arguments to a Python
> script for interpretation within the script (rather than by Python
> itself), so that I can use #!/usr/local/bin/python line at the top
> of the script file, and have the whole thing in a single file. Is
> there some way to stop Python interpreting command-line arguments,
> or some way to pass those arguments to a #!'ed script without them
> being examined by Python? A clean way would be preferred, but I'm
> willing to get grubby :-).

This is what I use. The script should be installed in your bin
directory with links to all the Python programs you want to have. The
Python code is in a file in some directory in your PYTHONPATH or in
the PYTHONDIR that is defined in the script.

--mysteryboxofun
Content-Type: application/octet-stream; charset=US-ASCII

#!/bin/sh

# Make sure your PATH is set.
PYTHONDIR=/ufs/sjoerd/lib/my-python # where the modules are

MODULE=`basename $0`

exec python -c "import sys;sys.path.insert(0,'$PYTHONDIR');sys.argv[:2]=['$MODULE'];import $MODULE" DUMMY ${1+"$@"}

--mysteryboxofun
Content-Type: text/plain

Sjoerd Mullender, CWI, P.O. Box 94079, 1090 GB Amsterdam, The Netherlands
E-Mail: Sjoerd.Mullender@cwi.nl; Phone: +31 20 592 4127; Fax: +31 20 592 4199
URL: <http://www.cwi.nl/cwi/people/Sjoerd.Mullender.html>

--mysteryboxofun--