The "loop and a half"

Gregory Ewing greg.ewing at canterbury.ac.nz
Sun Oct 8 08:07:22 EDT 2017


bartc wrote:
> Then you might have 'sort' for the non-interactive version, and 'isort' 
> or whatever for the interactive.

It's pretty rare that you'd want to use 'sort' interactively,
which is why your hypothetical 'isort' doesn't exist.

However, it *is* common to use it as part of a pipeline, which
is why it defaults to reading from stdin.

A consequence of that is that if you run it on its own,
without any arguments, it stops and waits for input from
the terminal. But it's not specifically designed to be
used that way, so it doesn't bother providing any prompts
in that situation.

> Except you simply wouldn't use an interactive version of any program 
> that reads an arbitrary long list of uninterrupted data, no matter how 
> the ending is indicated. You'd use a text editor, enter the lines at 
> your leisure, go back and forth to check and edit as needed, THEN you 
> would submit that file to 'sort'. As an actual input file.

In which case it won't 'hang', and you will be happy. :-)

> A program like 'python' might fit the bill too. Here, you can give it 
> the name of a file, OR say nothing, and it will take input from stdin.
> 
> Funnily enough, you now get a message, and a prompt. And when entering 
> multiple lines of code, you get a prompt before each line. You can also 
> terminate the sequence by entering a blank line.

Python goes to all that trouble because it's designed to be
used interactively, i.e. you can have a true conversation with
it. You can't really have a conversation with 'sort', since
it needs all the input before it can do anything.

-- 
Greg



More information about the Python-list mailing list