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字典遍历操作实例小结

本文实例讲述了Python字典遍历操作。分享给大家供大家参考,具体如下: 1 遍历键值对 可以使用一个 for 循环以及方法 items() 来遍历这个字典的键值对。 dict =...

用yum安装MySQLdb模块的步骤方法

前言 本文主要介绍的是用yum安装MySQLdb模块的步骤,下面话不多说了,来看看详细的介绍吧。 步骤如下 MySQLdb依赖于mysql-devel包,所以首先我们需要先安装mysql...

Python实现读取字符串按列分配后按行输出示例

本文实例讲述了Python实现读取字符串按列分配后按行输出。分享给大家供大家参考,具体如下: 问题: 输入一个字符串和一个数字,数字代表分为几行,需要按照给定的列存储方法存储下来之后按行...

python实现搜索本地文件信息写入文件的方法

python实现搜索本地文件信息写入文件的方法

本文实例讲述了python实现搜索本地文件信息写入文件的方法。分享给大家供大家参考,具体如下: 主要功能: 在指定的盘符,如D盘,搜索出与用户给定后缀名(如:jpg,png)相关的文件,...

Python pandas.DataFrame 找出有空值的行

Python pandas.DataFrame 找出有空值的行

0.摘要 pandas中DataFrame类型中,找出所有有空值的行,可以使用.isnull()方法和.any()方法。 1.找出含有空值的行 方法:DataFrame[DataFram...