python使用7z解壓apk包的方法
更新時間:2015年04月18日 14:30:39 作者:work24
這篇文章主要介紹了python使用7z解壓apk包的方法,涉及Python的shell命令調(diào)用技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了python使用7z解壓apk包的方法。分享給大家供大家參考。具體如下:
這段代碼通過shell調(diào)用7z對apk包進行解壓縮
def run_shell(command, mayFreeze=False):
def check_retcode(retcode, cmd):
if 0 != retcode:
print >> sys.stderr, 'err executing ' + cmd + ':', retcode
sys.exit(retcode)
def read_close(f):
f.seek(0)
d = f.read()
f.close()
return d
#print >> sys.stderr, '-- Executing', command
if mayFreeze:
tempout, temperr = tempfile.TemporaryFile(), tempfile.TemporaryFile()
#open(os.devnull, 'w')
p = subprocess.Popen(command, stdout=tempout, stderr=temperr)
p.wait()
output, errout = read_close(tempout), read_close(temperr)
else:
p=subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
output = p.stdout.read()
p.wait()
errout = p.stderr.read()
p.stdout.close()
p.stderr.close()
#check_retcode(p.returncode, command)
return (output.strip(), errout.strip())
#z7 is the full path to 7z.exe
#at times you have to encode the command into GBK/UTF8
run_shell(u'{0} -y -o"{1}" {2} x "{3}"'.format(z7, tempdir, icon, apk))
shutil.copy(u'{0}/{1}'.format(tempdir,os.path.basename(icon)),dst_path)
希望本文所述對大家的Python程序設計有所幫助。
相關文章
Python數(shù)據(jù)正態(tài)性檢驗實現(xiàn)過程
這篇文章主要介紹了Python數(shù)據(jù)正態(tài)性檢驗實現(xiàn)過程,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-04-04
利用python如何處理百萬條數(shù)據(jù)(適用java新手)
這篇文章主要給大家介紹了關于利用python如何處理百萬條數(shù)據(jù)的相關資料,本文的教程非常適用于java新手,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面隨著小編來一起學習學習吧2018-06-06
Python之tkinter面板PanedWindow的使用
這篇文章主要介紹了Python之tkinter面板PanedWindow的使用及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05
python數(shù)據(jù)可視化使用pyfinance分析證券收益示例詳解
這篇文章主要為大家介紹了python數(shù)據(jù)可視化使用pyfinance分析證券收益的示例詳解及pyfinance中returns模塊的應用,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-11-11
Python爬取數(shù)據(jù)并寫入MySQL數(shù)據(jù)庫的實例
今天小編就為大家分享一篇Python爬取數(shù)據(jù)并寫入MySQL數(shù)據(jù)庫的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-06-06

