Python: printing a file to stdout

后端 未结 8 1946
眼角桃花
眼角桃花 2020-12-08 03:55

I\'ve searched and I can only find questions about the other way around: writing stdin to a file :)

Is there a quick and easy way to dump the contents of a file to s

8条回答
  •  太阳男子
    2020-12-08 04:06

    If it's a large file and you don't want to consume a ton of memory as might happen with Ben's solution, the extra code in

    >>> import shutil
    >>> import sys
    >>> with open("test.txt", "r") as f:
    ...    shutil.copyfileobj(f, sys.stdout)
    

    also works.

提交回复
热议问题