- 论坛徽章:
- 0
|
本帖最后由 whynlight 于 2016-11-05 11:16 编辑
这段代码出自python简明教程,作用是把/whyn/test1/和/whyn/test2/中的文件备份到/whyn/testback/中,运行环境是sentos6.5,python版本是2.6.6,编辑器是vim,代码如下:
1 #!/usr/bin/python
2 #Filename:backup_ver1.py
3
4 import os
5 import time
6
7 source = ['/whyn/test1/','/whyn/test2/']
8
9 target_dir = '/whyn/testback/'
10
11 target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
12
13 zip_command = "zip -qr '%s' %s" % (target, ''.join(source))
14
15 if os.system(zip_command) == 0:
16 print 'Successful backup to',target
17 else:
18 print 'Backup FALLED'
第13行的代码,求解:
第一,"zip -qr '%s' %s"这两个%s是什么东西···
第二,% (target, ''.join(source))最前面这个%是什么意思,还有''.join(soruce)的两个单引号是做什么的
第三,zip_command = "zip -qr '%s' %s" % (target, ''.join(source))这一整行代码是不是把等号后面的一串东西全部赋值给zip_command?
这行代码看得有点懵,谢谢各位大牛啊·····
|
|