美文网首页
python中的文件小知识

python中的文件小知识

作者: 承諾過往雲煙 | 来源:发表于2018-07-15 20:32 被阅读0次

文件打开与关闭:
1 a =open("1.txt","r")
2 s= a.read()
3 n =open("2.txt","w")
4 n.write(s)
5 a.close()
6 n.close()
open 打开
read 读取
write 写
close 关闭

python的os模块

模块格式: import os

os.rename()#重命名
批量重命名
import os
a = input("请输入文件夹名:")
c=os.listdir(a)
os.chdir(a)
for i in c:
p = i.rfind(".") 运用字符串切片方法方便写入文件格式
s=i[:p]+"llala"+i[p:]
os.rename(i,s)

os,remove()#删除

相关文章

网友评论

      本文标题:python中的文件小知识

      本文链接:https://www.haomeiwen.com/subject/csfmpftx.html