Skip to content

Instantly share code, notes, and snippets.

@BastinRobin
Forked from AnnamalaiNagappan/conversion.py
Created September 26, 2016 17:00
Show Gist options
  • Save BastinRobin/7d7466fe7d83ebec0ac19f314d590919 to your computer and use it in GitHub Desktop.
Save BastinRobin/7d7466fe7d83ebec0ac19f314d590919 to your computer and use it in GitHub Desktop.
python script to convert all python .py files inside the current directory and all its subdirectories into .pyc and remove all .py files
import compileall
import os
# Get current working directory
curr_dir = os.getcwd()
# Compiles all python files to pyc
compileall.compile_dir(curr_dir, force=True)
# Recursively iterates to find .py files and remove them
for root, dirs, files in os.walk("."):
for file in files:
if file.endswith('.py'):
os.remove(os.path.join(root, file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment