【问题标题】:File.txt converted into a string [closed]File.txt 转换为字符串 [关闭]
【发布时间】:2021-06-09 02:48:14
【问题描述】:

我试图弄清楚如何将 file.txt 转换为字符串,以便我可以使用 find() 操作在 .txt 文件中查找某些文本。有谁知道如何使用 python 3 将 .txt 文件转换为字符串?

第一次在 Stack Overflow 上提问

-如果不好请见谅

【问题讨论】:

  • 您阅读过文档吗?试过什么?出了什么问题?

标签: python string file-conversion


【解决方案1】:
with open('file.txt', 'r') as thefile:
    string = thefile.read()

您可以参考Python docs on File I/O 或其他教程了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-28
    • 2018-05-02
    • 2011-06-14
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多