Python 3 教程 Python 文件 IO

sorin · 2022-03-15 13:56:32 · 热度: 7

以下代码演示了 Python 基本的文件操作,包括 open,read,write:

实例(Python 3.0+)

# Filename : test.py # author by : www.codercto.com # 写文件 with open("test.txt", "wt") as out_file: out_file.write("该文本会写入到文件中\n看到我了吧!") # Read a file with open("test.txt", "rt") as in_file: text = in_file.read() print(text)

执行以上代码输出结果为:

该文本会写入到文件中
看到我了吧!

查看更多 Python 实例

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册