A python script to remove comments from python scripts, with directory recursion
- Removes comments and docstrings
- Removes blank lines
- Can handle all files in a given directory
- Can attach a predefined header text to each output
- Non destructive - writes output to a separate file
-
See help :
python nocommentspython.py -h
-
Specify an input file to strip
python nocommentspython.py -i /path/to/inputfile.py
This will create an output file
inputfile.py_sanscomments.py
in the same directory as input file -
(Optional) Retain header section
python nocommentspython.py -i /path/to/inputfile.py -k yes
-
(Optional) Specify a header file to insert at the top of output file (Say, for copyright and licenses)
python nocommentspython.py -i /path/to/inputfile.py -c /path/to/headerfile.txt
-
Process all files in a directory :
python nocommentspython.py -i /path/to/directory
This will process each .py file in that directory and save its respective output file. If any input file has an associated header file, it will be duly inserted in its output file (see below).
Note
Header/Copyright Files: (Automatic headers for output)*
If an input file is named abcinput.py
, you can store its header text in a file
named abcinput.py_header.txt
in the same directory. This text will automatically be inserted in the output.
This is specially helpful for processing directories (see above).
© Rahul Singh