首页
学习
活动
专区
工具
TVP
发布
您找到你想要的搜索结果了吗?
是的
没有找到

python 文件操作

python基本的文件操作,包括 open,read,write 对文件操作流程: 1.打开文件,得到文件句柄并赋值给一个变量 2.通过句柄对文件进行操作 3.关闭文件  新建一个txt文件,内容是《Yesterday...When I Was Young》一首歌的歌词 内容如下: Somehow, it seems the love I knew was always the most destructive kind Yesterday...编码不匹配,所以,打开文件时,要指定编码 data = open("Yesterday.txt",encoding="utf-8").read() print(data) 再次执行,就不会报错了。...执行报错 io.UnsupportedOperation: not readable 因为w 只能写入,不能读取 同时,Yesterday.txt文件内容被清空了。...把上面的歌词重新复制到Yesterday.txt中 读取前5行 f = open("Yesterday.txt",'r',encoding="utf-8") for i in range(5):

75020

扫码

添加站长 进交流群

领取专属 10元无门槛券

手把手带您无忧上云

扫码加入开发者社群

相关资讯

热门标签

活动推荐

    运营活动

    活动名称
    广告关闭
    领券