Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104556
| From | Fillmore <fillmore_remove@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Other difference with Perl: Python scripts in a pipe |
| Date | 2016-03-10 17:04 -0500 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <nbsr1n$5va$1@gioia.aioe.org> (permalink) |
| References | <nbsp83$2p1$1@gioia.aioe.org> <mailman.157.1457646452.15725.python-list@python.org> |
On 3/10/2016 4:46 PM, Ian Kelly wrote:
> On Thu, Mar 10, 2016 at 2:33 PM, Fillmore <fillmore_remove@hotmail.com> 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):
> sys.stdout.write('line %d\n' % i)
you are right. it's the with block :(
import sys
import csv
with open("somefile.tsv", newline='') as csvfile:
myReader = csv.reader(csvfile, delimiter='\t')
for row in myReader:
for i in range(20):
sys.stdout.write('line %d\n' % i)
$ ./somescript.py | head -5
line 0
line 1
line 2
line 3
line 4
Traceback (most recent call last):
File "./somescript.py", line 12, in <module>
sys.stdout.write('line %d\n' % i)
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w'
encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Other difference with Perl: Python scripts in a pipe Fillmore <fillmore_remove@hotmail.com> - 2016-03-10 16:33 -0500
Re: Other difference with Perl: Python scripts in a pipe Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-10 14:46 -0700
Re: Other difference with Perl: Python scripts in a pipe Fillmore <fillmore_remove@hotmail.com> - 2016-03-10 17:04 -0500
Re: Other difference with Perl: Python scripts in a pipe Peter Otten <__peter__@web.de> - 2016-03-10 23:09 +0100
Re: Other difference with Perl: Python scripts in a pipe Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-10 15:16 -0700
Re: Other difference with Perl: Python scripts in a pipe Fillmore <fillmore_remove@hotmail.com> - 2016-03-10 18:48 -0500
Re: Other difference with Perl: Python scripts in a pipe INADA Naoki <songofacandy@gmail.com> - 2016-03-11 09:08 +0900
Re: Other difference with Perl: Python scripts in a pipe Fillmore <fillmore_remove@hotmail.com> - 2016-03-10 19:26 -0500
Re: Other difference with Perl: Python scripts in a pipe Alan Bawden <alan@csail.mit.edu> - 2016-03-11 01:45 -0500
Re: Other difference with Perl: Python scripts in a pipe Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-11 12:15 +0200
Re: Other difference with Perl: Python scripts in a pipe Ethan Furman <ethan@stoneleaf.us> - 2016-03-11 00:55 -0800
csiph-web