Skip to content

Instantly share code, notes, and snippets.

@AnnamalaiNagappan
Created September 26, 2016 12:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AnnamalaiNagappan/655db51d2d4766a923e5332e16813a95 to your computer and use it in GitHub Desktop.
Save AnnamalaiNagappan/655db51d2d4766a923e5332e16813a95 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))
@BastinRobin
Copy link

Its a wonderful code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment