[Python-ideas] A better interactive prompt

Steven D'Aprano steve at pearwood.info
Wed Oct 26 20:01:50 EDT 2016


On Wed, Oct 26, 2016 at 02:40:36PM -0700, Nikolaus Rath wrote:

> It also imposes a significant burden on scripting. 

"It" being a configurable REPL.

> I often have elements like this in shell scripts:
> 
> output=$(python <<EOF
> import h5py
> with h5py.File('foo', 'r') as fh:
>      print((fh['bla'] * fh['com']).sum())
> EOF
> )
> 
> If this now starts up IPython, it'll be *significantly* slower.

Surely this won't be a real problem in practice. Unless you give -i as a 
command line switch, calling Python as a script shouldn't need to 
run the REPL.

But even if it did, if Python's REPL was configurable, there has to be a 
way to configure it. And presumably by default it would fall back to the 
standard vanilla REPL. So "python" in your shell script will probably 
refer to "the system Python, using the default REPL" rather than 
whatever personalised Python + REPL your own personal environment sets 
up for when you type "python" at the shell prompt.

And if not, then something like this:

output=$(python --use-std-repl <<EOF
...


may be all you need.



-- 
Steve


More information about the Python-ideas mailing list