Chinaunix首页 | 论坛 | 博客
  • 博客访问: 436888
  • 博文数量: 89
  • 博客积分: 2713
  • 博客等级: 少校
  • 技术积分: 938
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-18 21:19
个人简介

为了成为自由自在的人而奋斗!

文章分类

全部博文(89)

文章存档

2016年(5)

2015年(9)

2014年(2)

2013年(10)

2012年(1)

2011年(30)

2010年(32)

分类: Python/Ruby

2013-09-26 23:13:11

使用python作一个简单的备份

点击(此处)折叠或打开

  1. #!/usr/bin/env python
  2. # Filename: backup_ver1.py

  3. import os
  4. import time

  5. # 1. 备份的目录及文件列表
  6. source=['./src/1.txt','./src/2.txt']
  7. # If you are using Windows, use source=[r'C:\Documents',r'D:\Work'] or something like that

  8. # 2. 备份目标目录
  9. target_dir='./bak/' #Remember to change this to what you will be using

  10. # 3. The files are backed up into a zip file
  11. # 4. The name of the zip archive is the current date and time
  12. target=target_dir+time.strftime('%Y%m%d%H%M%S')+'.zip'

  13. # 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
  14. zip_command="zip -qr '%s' %s" %(target,' '.join(source))

  15. # Run the backup
  16. if os.system(zip_command)==0:
  17.     print ('Successful backup to', target)
  18. else:
  19.     print ('Backup FAILED')
  20. 结果:
  21. >>> ================================ RESTART ================================
    >>> 
    Successful backup to ./bak/20130926225932.zip
    >>> 




python---类
使用class name:定义一个类
类方法 比普通函数多一个self参数,由类自动传入,不需要手动传入
__init__ 类的构造函数

类的继承,父类由括号包含起来
class child(parent):
父类的constructor函数不会被子类自动调用,需要显式的调用。



阅读(1153) | 评论(0) | 转发(0) |
0

上一篇: pythons基础学习-4

下一篇:cygwin编译boost

给主人留下些什么吧!~~