【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)效果如下:
# -*- 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】整理一些实用的函数
- 【python】整理一些实用的函数
- 【python】整理一些实用的函数
- 【python】整理一些实用的函数
- 【python】整理一些实用的函数
- 【python】整理一些实用的函数
- 【python】整理一些实用的函数
- 【python】整理一些实用的函数
- 【python】整理一些实用的函数
- 整理一些实用的函数
- scrapy一些非常实用资料整理,与其他mongdb、django、redis、solr、tor结合使用以及用Python脚本调用等等方法
- python里一些实用的函数
- MATLAB 图像处理一些实用函数整理
- Xman整理篇___关于Python的一些基础方法及函数
- Python中非常实用的一些功能和函数分享
- Python中非常实用的一些功能和函数分享
- python justtest中一些小函数的整理,以备查用
- i结点缓冲管理和一些相关实用的函数
- Python 一些函数介绍
- linux中C编程的一些时间函数整理