PYTHON - Remove commented lines from .py code files

Posted in Programming by v.udartsev on 24 September 2020

1. Create clear.sh file with:

#!/bin/sh
FILES=$(find . -name "*.py" -not -path "./env/*")
for FILE in $FILES
    do
        sed '/""".*"""/d;s/#.*$//;s/^\n$/\n/' $FILE > temp.txt && mv temp.txt $FILE
        echo "Processed file: $FILE"
    done
exit 0

2. Copy in in /your_project_root_foder/ and run:

    sh clear.sh