首页 > 编程语言 > 详细

Python入门者小练习

时间:2015-03-30 13:09:40      阅读:259      评论:0      收藏:0      [点我收藏+]

练习适用于LINUX,类Unix系统,一步一个脚印提高Python 。

 

001. 类Unix系统中用zip命令将文件压缩备份至 /temporary/ 目录下:

import os
import time

old_files = [/home/zhg/aa.py,home/zhg/bb.py]
target_dir = /temporary/
target = target_dir + time.strftime(%Y%m%d%H%M%S) + .zip
zip_command = "zip -qr %s %s" % (target, .join(old_files))

if os.system(zip_command) == 0:
    print "Successful backup to",target_dir
else:
    print "error backup failed"

#  Linux中上一次命令执行成功会返回0  

#  ‘  ‘.join(sequence)方法见: 字符串方法

 

Python入门者小练习

原文:http://www.cnblogs.com/zhanhg/p/4377518.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!