Re: Other difference with Perl: Python scripts in a pipe

2016-03-11 Thread Jussi Piitulainen
Alan Bawden writes: > Fillmore writes: > >> On 3/10/2016 7:08 PM, INADA Naoki wrote: > ... >> I don't like it. It makes Python not so good for command-line utilities >> > > You can easily restore the standard Unix command-line-friendly behavior > by doing: > > import signal > signal.signal(

Re: Other difference with Perl: Python scripts in a pipe

2016-03-11 Thread Ethan Furman
On 03/10/2016 04:26 PM, Fillmore wrote: On 3/10/2016 7:08 PM, INADA Naoki wrote: No. I see it usually. Python's zen says: Errors should never pass silently. Unless explicitly silenced. When failed to write to stdout, Python should raise Exception. You can silence explicitly when it's

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Alan Bawden
Fillmore writes: > On 3/10/2016 7:08 PM, INADA Naoki wrote: ... > I don't like it. It makes Python not so good for command-line utilities > You can easily restore the standard Unix command-line-friendly behavior by doing: import signal signal.signal(signal.SIGINT, signal.SIG_DFL) si

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
On 3/10/2016 7:08 PM, INADA Naoki wrote: No. I see it usually. Python's zen says: Errors should never pass silently. Unless explicitly silenced. When failed to write to stdout, Python should raise Exception. You can silence explicitly when it's safe: try: print(...) except Broken

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread INADA Naoki
On Fri, Mar 11, 2016 at 8:48 AM, Fillmore wrote: > On 3/10/2016 5:16 PM, Ian Kelly wrote: > >> >> Interesting, both of these are probably worth bringing up as issues on >> the bugs.python.org tracker. I'm not sure that the behavior should be >> changed (if we get an error, we shouldn't just swall

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
On 3/10/2016 5:16 PM, Ian Kelly wrote: Interesting, both of these are probably worth bringing up as issues on the bugs.python.org tracker. I'm not sure that the behavior should be changed (if we get an error, we shouldn't just swallow it) but it does seem like a significant hassle for writing co

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Ian Kelly
On Thu, Mar 10, 2016 at 3:09 PM, Peter Otten <__pete...@web.de> wrote: > I suppose you need to fill the OS-level cache: > > $ cat somescript.py > import sys > > for i in range(int(sys.argv[1])): > sys.stdout.write('line %d\n' % i) > $ python somescript.py 20 | head -n5 > line 0 > line 1 > line

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Peter Otten
Ian Kelly wrote: > On Thu, Mar 10, 2016 at 2:33 PM, Fillmore > wrote: >> >> when I put a Python script in pipe with other commands, it will refuse to >> let go silently. Any way I can avoid this? > > What is your script doing? I don't see this problem. > > ikelly@queso:~ $ cat somescript.py > i

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
On 3/10/2016 4:46 PM, Ian Kelly wrote: On Thu, Mar 10, 2016 at 2:33 PM, Fillmore wrote: when I put a Python script in pipe with other commands, it will refuse to let go silently. Any way I can avoid this? What is your script doing? I don't see this problem. ikelly@queso:~ $ cat somescript.p

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Ian Kelly
On Thu, Mar 10, 2016 at 2:33 PM, Fillmore wrote: > > when I put a Python script in pipe with other commands, it will refuse to > let go silently. Any way I can avoid this? What is your script doing? I don't see this problem. ikelly@queso:~ $ cat somescript.py import sys for i in range(20):

Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Fillmore
when I put a Python script in pipe with other commands, it will refuse to let go silently. Any way I can avoid this? $ python somescript.py | head -5 line 1 line 3 line 3 line 4 line 5 Traceback (most recent call last): File "./somescript.py", line 50, in sys.stdout.write(row[0]) Broken