python使用7z解压apk包的方法

yipeiwu_com6年前Python基础

本文实例讲述了python使用7z解压apk包的方法。分享给大家供大家参考。具体如下:

这段代码通过shell调用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 tkinter模块弹出窗口及传值回到主窗口操作详解

Python tkinter模块弹出窗口及传值回到主窗口操作详解

本文实例讲述了Python tkinter模块弹出窗口及传值回到主窗口操作。分享给大家供大家参考,具体如下: 有些时候,我们需要使用弹出窗口,对程序的运行参数进行设置。有两种选择 一、标...

django模板加载静态文件的方法步骤

加载静态文件 在一个网页中,不仅仅只有一个 html 骨架,还需要 css 样式文件, js 执行文件以及一些图片等。因此在 DTL 中加载静态文件是一个必须要解决的问题。在 DTL 中...

Python OpenCV中的resize()函数的使用

Python OpenCV中的resize()函数的使用

改变图像大小意味着改变尺寸,无论是单独的高或宽,还是两者。也可以按比例调整图像大小。 这里将介绍resize()函数的语法及实例。 语法 函数原型 cv2.resize(src, d...

python join方法使用详解

join方法 join这个方法,将可迭代的数据类型,转为字符串或者bytes,没错可以转为bytes类型。注意这个可迭代的数据中的元素必须是相同类型的。 jion里的参数可迭代对象就行...

python使用matplotlib画柱状图、散点图

python使用matplotlib画柱状图、散点图

本文实例为大家分享了python使用matplotlib画柱状图、散点图的具体代码,供大家参考,具体内容如下 柱状图(plt.bar) 代码与注释 import numpy as n...