sys.stdin on windows

zugnush at zugnush at
Wed Sep 3 11:16:03 CEST 2008

I often grep particular patterns out of large logfiles and then
pipeline the output to sort and uniq -c
I thought today to knock up a script to do the counting in a python

This seems work in linux

$ cat
#!/usr/bin/env python
import sys
from collections import defaultdict
for line in sys.stdin.readlines():
print "contents,count"
for key in accumulator.keys():
    print key,",",accumulator[key]

$ cat test | ./
 , 1
23 , 1
1 , 1
3 , 2
2 , 2
5 , 3

When I try to run the same thing on windows I get
IOError: [Error 9] Bad file descriptor

How can I make this more windows friendly?


More information about the Python-list mailing list