python学习之课后习题
来源:互联网 发布:mac 水漾润泽 编辑:程序博客网 时间:2024/06/09 19:53
编写一个动态备份文件的python脚本:
#!/usr/bin/python#filename :backup_ver2.pyimport osimport timeimport syssource=[]for i in sys.argv: print i source.append(i)#source=['/root/python/test.py','/root/python/backup_var1.py']print sourcedel(source[0])print '#######'print sourcetarget_dir='/root/python/'today=target_dir+time.strftime('%Y%m%d')now=time.strftime('%H%M%S')if not os.path.exists(today): os.mkdir(today) print 'successfully created directory', todaytarget=today+os.sep+now+'.zip'zip_command="zip -qr '%s' %s" %(target,' '.join(source))#run the backupif os.system(zip_command)==0: print 'successfully backup to the target',targetelse: print 'failed backup'这里利用list的可增可减的特性,进过反复的实验,发现使用sys.argv的方法后会把本身的py脚本也包裹到里面如下:
[root@fsailing1 python]# python backup_ver2.py /root/python/test.py /root/python/while.pybackup_ver2.py/root/python/test.py/root/python/while.py['backup_ver2.py', '/root/python/test.py', '/root/python/while.py']successfully backup to the target /root/python/20120627/203320.zip所以使用了del的方法进行删除了,这样就会好点儿了。
[root@fsailing1 python]# python backup_ver2.py /root/python/test.py /root/python/while.pybackup_ver2.py/root/python/test.py/root/python/while.py['backup_ver2.py', '/root/python/test.py', '/root/python/while.py']#######['/root/python/test.py', '/root/python/while.py']successfully backup to the target /root/python/20120627/203634.zip
- python学习之课后习题
- Python 课后习题^-^
- Python学习笔记: 第五章课后习题练习
- 可爱的python课后习题
- c++Primer学习笔记之四:第一章课后习题
- c++Primer学习笔记之七:第二章课后习题
- IOS学习---课后习题1
- 可爱的python课后习题(二)
- 可爱的python课后习题(三)
- Python核心编程第二章课后习题
- python核心编程第五章课后习题
- Python课后习题-第八章 读写文件
- 【鱼C·零基础入门学习Python】课后习题答案 第14课
- Python学习之《python核心编程》 第二章课后答案
- Python学习之《python核心编程》 第二章课后答案
- 学习Opencv第3章课后习题
- 学习Opencv第2章课后习题
- 学习Opencv第4章课后习题
- WINCE系统中coredll.dll有什么用?
- java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI(xxx
- VC++设计托盘图标程序
- 怎样让Win7显示桌面
- C++运算符重载探讨
- python学习之课后习题
- DDB与DIB
- 和菜鸟一起学android4.0.3源码之touchscreen配置+调试记录
- 2012年最受欢迎的PHP框架
- Oracle Goldengate ORA-21780故障处理
- 字符转换(2,8,10,16进制,ASCII码)
- 大型机汇编(mainframe assembler/HLASM)之DUMP解读
- ogg replicat 进程 abend 处理
- 2.8.2 Wi n d o w s定义的U n i c o d e数据类型