Python如何调用rar命令
爱喝马黛茶的安东尼
2019-09-21 17:47:005180浏览 · 0收藏 · 0评论
通过os模块的system()方法调用了系统的rar.exe命令,这个方法会返回一个变量exit_status。
相关推荐:《Python教程》
import os import time source = [r‘D:\Work\Python\Demo‘, ‘d:\\work\\linux‘] target_dir = ‘D:\\Work\\backup\\‘ target = target_dir + time.strftime(‘%Y%m%d%H%M%S‘) + ‘.rar‘ zip_command = "rar a %s %s" % (target, ‘ ‘.join(source)) if os.system(zip_command) == 0: print ‘Sucessful backup to‘, target else: print ‘Backup Failed‘
关注公众号,随时随地在线学习