Python:将文件打印到标准输出 [英] Python: printing a file to stdout

查看:55
本文介绍了Python:将文件打印到标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索过,但只能找到相反的问题:将标准输入写入文件 :)

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 stdout?

推荐答案

好的.假设您有一个名为 fname 的文件名字符串,下面的操作就可以了.

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())

这篇关于Python:将文件打印到标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆