How do I write a unix filter in python?

前端 未结 4 689
梦毁少年i
梦毁少年i 2021-01-04 08:44

I want to write a program that reads stdin (unbuffered) and writes stdout (unbuffered) doing some trivial char-by-char transformation. For the sake of the example let\'s say

4条回答
  •  孤独总比滥情好
    2021-01-04 09:18

    Read from sys.stdin and write to sys.stdout (or use print). Your example program:

    import sys
    
    for line in sys.stdin:
        print line.replace("x", ""),
    

    There isn't a standard way to make stdin unbuffered, and you don't want that. Let the OS buffer it.

提交回复
热议问题