[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The "loop and a half"

On 06/10/2017 12:51, Chris Angelico wrote:
> On Fri, Oct 6, 2017 at 10:41 PM, bartc <bc at freeuk.com> wrote:

 > What you REALLY mean is that you can't see the point of an interactive
 > sort command. It doesn't fit into your workflow. And that's fine. It's
 > not something you'd use very often. There are other programs, however,
 > that behave exactly the same whether used in batch mode or interactive
 > mode, and where you would do exactly the same thing as I described -
 > provide input, and hit Ctrl-D to mark that you're done.


And is there any reason why you wouldn't use a text editor to capture 
your input first? I can see myself noticing an error I'd made 10 lines 
up, which is now too late to change, and I've still got 100 lines to go. 
What to do?

I just can't anyone wanting to use programs that work in the way you 
suggest. Not outside of a student exercise (read N numbers and display 
the average), where getting the input correct isn't so important.

 > And since
 > every one of these programs is written to read from stdin until EOF,
 > you can use them all in exactly the same way - type at keyboard, hit
 > Ctrl-D when done.

So they're all at it! That doesn't mean it's a good way of doing things.

>> So it IS possible to do it properly after all!)
> Actually, Python's interactive mode is completely different from its
> file input mode. You're not really comparing like things here.
> Python's incremental interpreter is *by nature* interactive, and
> redirecting its input does not produce the same result as running
> "python3 filename.py" would. Can you find yourself a better example?

I gave the FTP example. (Which actually, in my version, doesn't work 
properly when trying redirect input into it. You have to give an actual 
file name.)

But what's wrong with the Python example? It detects when it's given a 
file (as as actual parameter, or redirected), and when it's used 
interactively, and adapts its behaviour accordingly.

It just needs a bit of effort.