安装uncompyle6
pip install uncompyle6
命令行使用:转化filename.pyc
uncompyle6 -o filename.py filename.pyc
批量转化给定目录下的所有pyc文件
典型案例:pyc文件分布在不同子目录下,我们需要逐层遍历,将每一个pyc文件分别转化成一个同名的py文件。
import os
import sys
def walk_dir(dir,topdown=True):
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)
print(part_file_name)
os.system('uncompyle6 -o %s.py %s.pyc'%(part_file_name,part_file_name))
if __name__ == '__main__':
dirname = "D:\dirname"
walk_dir(dirname)
网友评论