#coding:UTF-8
import os
import time
source=['test_module.py','test_module.pyc']
target_dir='';
today=target_dir+time.strftime('%Y%m%d')
now=time.strftime('%H%M%S')
comment=raw_input('Enter a comment ')
if len(comment)==0:
target=today+os.sep+now+'.zip'
else:
target=today+os.sep+now+'_'+\
comment.replace(' ','_')+'.rar'
if not os.path.exists(today):
os.mkdir(today)
print 'Successfully created directory',today
zip_command='rar a %s %s'%(target,'test_module.py')
print zip_command
if os.system(zip_command)==0:
print 'Successful backup to',target
else:
print 'Backup failed'
注释:命令打印出来在cmd下可以执行,但是这样无法执行,不知道为什么。。。。