python text file to string

纯净搜索 为您找到 本页 3 条,用时 0 秒(数据源:360)

AI 回答 由 glm-4-flash 生成 · 仅供参考,请自行核实
1. 使用`open()`函数打开文件。
2. 使用`read()`方法读取文件内容。
3. 将读取的内容转换为字符串。

代码示例:

with open('example.txt', 'r') as file:
content = file.read()
text_string = str(content)