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安装scrapy的正确姿势

详解Python安装scrapy的正确姿势

运行平台:Windows Python版本:Python3.x IDE:Sublime text3 一、Scrapy简介 Scrapy是一个为了爬取网站数据提取结构性数据而编写的应用框架...

python 多进程通信模块的简单实现

多进程通信方法好多,不一而数。刚才试python封装好嘅多进程通信模块 multiprocessing.connection。 简单测试咗一下,效率还可以,应该系对socket封装,效率...

python 实现将字典dict、列表list中的中文正常显示方法

在代码文件中定义中文时,经常会遇到问题,要么编码错误,要么是无法正常打印显示。 例如,dict_chinese.py: #!/usr/bin/python a={'name': 'f...

详解使用 pyenv 管理多个版本 python 环境

 随着同时开发的项目越来越多,需要不停的在各个不同版本的 python 环境之间切换,所以想到了pyenv。以前一直使用的 virtualenv只能管理同一个 python 版...

Tensorflow实现神经网络拟合线性回归

Tensorflow实现神经网络拟合线性回归

本文实例为大家分享了Tensorflow实现神经网络拟合线性回归的具体代码,供大家参考,具体内容如下 一、利用简单的一层神经网络拟合一个函数 y = x^2 ,其中加入部分噪声作为偏置值...