passing an option to the python interpreter
rosuav at gmail.com
Sat Feb 15 23:50:36 CET 2014
On Sun, Feb 16, 2014 at 9:32 AM, Jabba Laci <jabba.laci at gmail.com> wrote:
> #!/usr/bin/env python -u
> But if I want to run it from the command line ($ ./unbuffered.py), I
> get this error:
> /usr/bin/env: python -u: No such file or directory
> env is looking for "python -u" but such a command doesn't exist.
> How to overcome this problem? I could write
> #!/usr/bin/python -u
That's a fundamental limitation with the shebang syntax: you can pass
exactly one argument. Passing more than one is platform-dependent -
some Unixes will pass multiple args, some will pass the whole string
as a single arg (which is what you're seeing here), and I think some
will discard everything from the space onward.
What you could do is add a wrapper called 'pythonu'.which invokes 'env
python -u %*'. Be aware, though, that shebanging to a shell script
isn't safe either; modern Linuxes support it, but to be truly
cross-platform, you'd have to write pythonu in a compiled language and
make a binary.
More information about the Python-list