This article will explain in detail about Python How to batch decompile pyc turn py, Xiaobian thinks it's very practical , So share it for your reference , I hope you can gain something after reading this article .
pyc It's a binary file , By py The file is compiled , Generated files , It's a kind of byte code,py File becomes pyc After the document , The loading speed has increased , and pyc It's a cross platform bytecode , By python The virtual machine to execute , This is similar to JAVA perhaps .NET The concept of virtual machine .
Use uncompyle6 Can be pyc The file is converted to py file , therefore , You can also call CMD Carry out batch operation , The code is as follows :
import os
import sys
def walk_dir(dir,topdown=True):
words=[]
words=['asyncio.','attr.','bs4.','chardet.','Crypto.','chardet.','concurrent.','ctypes.','dateutil.','distutils.','email.','et_xmlfile.','fiona.','geographiclib.','geojson.','geopandas.','geopy.','html.','http.','importlib.','jinja2.','multiprocessing.','numpy.','openpyxl.','pandas.','pkg_resources.','pyecharts.','pyproj.','pytz.','requests.','setuptools.','shapely.','simplejson.','soupsieve.','sqlalchemy.','unittest.','urllib3.','xlsxwriter.','xml.','xlrd.']
for root, dirs, files in os.walk(dir, topdown):
for name in files:
if name.endswith('.pyc'):
part_name = name[0:-4]
part_file_name = os.path.join(root, part_name).replace("\\","/")
isconvert=True
for w in words:
if (name.startswith(w)):
isconvert=False
break
if isconvert:
os.system('uncompyle6 -o "%s.py" "%s.pyc"'%(part_file_name,part_file_name))
print(part_file_name)
walk_dir(os.getcwd())
About “ stay Python How to batch decompile pyc turn py” This article is shared here , I hope the above contents can be of some help to you , So that you can learn more , If you think the article is good , Please share it for more people to see .