第10章 解决问题——编写一个Python脚本解决方案 第四个方案,对比例子,我修改了一下,但是仍然对os.system()的路径空格问题有些迷惑:(# Filename: backup_ver4.py # rar dir to c:/test/20100720/210656_abc.rar import os import time source = ['c://360','c://360Downloads'] target_dir = 'c://test//' today = target_dir + time.strftime('%Y%m%d') now = time.strftime('%H%M%S') comment = raw_input('Enter a comment:') if len(comment) == 0: filepath = today + os.sep + now + '.rar' else: filepath = today + os.sep + now + '_' + comment.replace(' ','_') + '.rar' if not os.path.exists(today): os.mkdir(today) print 'Creat Dir',today rarcmd = 'rar.exe a -r -inul %s %s' % (filepath,' '.join(source)) if os.system(rarcmd) == 0: print 'succesful backup to', filepath else: print 'backup failed'