3.308 参考/文件 IO

Python 文件 IO

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

实例(Python 3.0+)

# Filename : test.py
# author by : www.nowcoder.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)

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

该文本会写入到文件中
看到我了吧!
全部评论

相关推荐

牛至超人:您好,京东物流岗了解一下吗?负责精加工食品的端到端传输
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务