Python: printing a file to stdout

后端 未结 8 1951
眼角桃花
眼角桃花 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:12

    Sure. Assuming you have a string with the file's name called fname, the following does the trick.

    with open(fname, 'r') as fin:
        print(fin.read())
    

提交回复
热议问题