Choose a folder.
Run ptt.py and enter the folder containing the files to convert.
Python to Textfile
Copy Python and JSON files to text while preserving their folder structure, making a collection of source files easier to organize.
├ main.py
└ config.json├ main.txt
└ config.txtRun ptt.py and enter the folder containing the files to convert.
Find Python and JSON files and copy them with a .txt extension. Original files remain in place.
Results are saved in a dated folder beside the script. Same-name .py and .json files in one folder can map to the same output file.
What the script actually does, how the output is laid out, and what to watch for, straight from the source.
ptt.py finds every .py and .json file in a folder and all its subfolders and makes copies with a .txt extension. Originals stay untouched. It uses only Python’s standard library.
It is handy when you need to share code somewhere that won’t accept .py or .json uploads, or want to skim a project’s source as plain text.
Each run creates a new folder named by date_time inside python-to-textfile/ next to the script, keeping the original folder structure. File metadata such as modification time is copied too (shutil.copy2).
project/ python-to-textfile/2025-04-11_16-19-56/
├─ main.py → ├─ main.txt
└─ app/ └─ app/
├─ api.py ├─ api.txt
└─ config.json └─ config.txtWhen it finishes it reports how many of the files found were copied. If you don’t pass a path as an argument, it asks for one.
.py and a .json with the same name (say config.py and config.json), both become config.txt and the JSON copy, made second, overwrites the first.extensions list in the source (default ['.py', '.json']).Just Python 3. Clone the repository and run python3 ptt.py or python3 ptt.py path.
No. It only makes copies and never touches the originals.
Run with Python 3. The script will ask for the folder path.
git clone https://github.com/Seokwoooo/Python-To-Textfile.git
cd Python-To-Textfile
python3 ptt.pyRead the full guide on GitHub ↗