Python文件处理 X模式(day_012)

X:只写模式,不存在则创建,存在则报错。
该模式了解即可,鸡肋一个!

with open('d.txt',mode='x',encoding='utf-8') as f:
    # f.read()  # 该模式不可读!
    f.write('程序猿过家家\n')
发布了24 篇原创文章 · 获赞 2 · 访问量 401

猜你喜欢

转载自blog.csdn.net/weixin_46491071/article/details/104907348