品易云推流 关闭
文章详情页
文章 > Python基础教程 > Python如何调用rar命令

Python如何调用rar命令

Python 调用 rar 命令

头像

爱喝马黛茶的安东尼

2019-09-21 17:47:004359浏览 · 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‘
关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图