您的位置:首页 > 编程语言 > Python开发

【python】整理一些实用的函数

2018-03-10 19:37 627 查看
备份函数:#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import datetime

import shutil

def backup_txt_rename(txt_path):
if os.path.exists(txt_path):
i = datetime.datetime.now()
date = str(i.year) + str("%02d"%i.month) + str("%02d"%i.day) + str("%02d"%i.hour) + str("%02d"%i.minute) + str("%02d"%i.second)
new_name = txt_path +".bak" + date
os.rename(txt_path, new_name)
print("copied and deleted file, new_name = {}".format(new_name))explain:1)txt 文件备份,当文件存在时,先备份再生成相同的文件名;
2)txt_path:文件路径,如:"/home/reserch/documents/deeplearning/alzheimers_disease_DL/pytorch/subject_id/test/file.txt"3)效果如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 函数