【问题标题】:How to display a text file in the terminal with python [closed]如何使用python在终端中显示文本文件[关闭]
【发布时间】:2023-03-27 14:49:01
【问题描述】:

我的文件夹中有 2 个文件:
text.txt
main.py

我想在运行main.py 时在终端中显示用text.txt 编写的文本。 我该怎么做?

【问题讨论】:

  • 请从intro tour 重复on topichow to ask。 “告诉我如何解决这个编码问题?”与 Stack Overflow 无关。您必须诚实地尝试解决方案,然后就您的实施提出具体问题。 Stack Overflow 无意取代现有的教程和文档。

标签: python python-3.x text printf


【解决方案1】:
with open('text.txt', 'r') as f:
    print(f.read())

【讨论】:

    猜你喜欢
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    • 2017-11-20
    • 2014-04-19
    • 2012-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多