Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncompyle6 convert pyc to py file python 3 (Whole directory)

I have 200 pyc files I need to convert in a folder. I am aware of converting pyc to py files through uncompyle6 -o . 31.pyc however as I have so many pyc files, this would take a long period of time. I've founds lots of documentation but not much in bulk converting to py files. uncompyle6 -o . *.pyc was not supported.

Any idea on how I can achieve this?


2 Answers

This is natively supported by uncompyle6

uncompyle6 -ro <output_directory> <python_directory>
  • -r tells the tool to recurse into sub directories.
  • -o tells the tool to output to the given directory.
like image 179
CaptainBumbleFudge Avatar answered Oct 29 '25 04:10

CaptainBumbleFudge


Might not be perfect but it worked great for me.

import os
import uncompyle6
your_directory = ''
for dirpath, b, filenames in os.walk(your_directory):
    for filename in filenames:
        if not filename.endswith('.pyc'):
            continue

        filepath = dirpath + '/' + filename
        original_filename = filename.split('.')[0]
        original_filepath = dirpath + '/' + original_filename + '.py'
        with open(original_filepath, 'w') as f:
            uncompyle6.decompile_file(filepath, f)
like image 38
Steinfeld Avatar answered Oct 29 '25 02:10

Steinfeld



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!