Python 如何提升py文件版本

版权声明:zhaojanc https://blog.csdn.net/qq_38641985/article/details/84756318

假如你建立了一个目录,新建了一个py文件,之后你想要备份这个文件,如果直接拷贝文件就会出现副本等,不想这样还要手动修改,因此写了一个脚本。

#!coding=utf-8
import os
import re
root = os.path.dirname(__file__)
num=0
for f in os.listdir(root):
    match=re.compile(".+\d+.py")
    result=match.findall(f)
    
    if result!=[]:
        num=num+1
        temp = result[0]

n1=temp.split('.')[0]
n2= filter(lambda x:x not in '0123456789',n1)
n3=n2+str(num+1)+".py"
f=open(n3,'w')
f.write("#*******************************************\n")
f.write("#*******************************************\n")
f.write("#*******************************************\n")
f.write("#coding:utf-8\n")

for i in range(20):
	f.write("\n")

f.write("#*******************************************\n")
f.write("#*******************************************\n")
f.write("#*******************************************\n")
f.close()

在这里插入图片描述
python_yunwei7.py
在这里插入图片描述
如果不喜欢这个形式可以自定义py格式和内容。

猜你喜欢

转载自blog.csdn.net/qq_38641985/article/details/84756318