Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66491

Re: passing an option to the python interpreter

References <CAOuJsMmwOAatTO7Hsx3eYDoo31D81rBJBfnYb6Me-Z09EjORcw@mail.gmail.com>
Date 2014-02-16 09:50 +1100
Subject Re: passing an option to the python interpreter
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.7027.1392504640.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Feb 16, 2014 at 9:32 AM, Jabba Laci <jabba.laci@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.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: passing an option to the python interpreter Chris Angelico <rosuav@gmail.com> - 2014-02-16 09:50 +1100

csiph-web