0
点赞
收藏
分享

微信扫一扫

python文件操作

跟着Damon写代码 2022-02-03 阅读 75

在python中文件操作有很多中方式,在python3中对过去的文件操作简化,以下实例是python3中的写法

实例

# 写入
with open("./test.txt","w",encoding="utf-8") as fp:
    fp.write(a)
    fp.close()
    print("写入成功!")
# 读取
with open("./test.txt","r",encoding="utf-8") as fp:
    print(fp.read())
    fp.close()

操作模式

打卡第42天,对python大数据感兴趣的朋友欢迎一起讨论、交流,请多指教!

举报

相关推荐

0 条评论