Data Format Conversions

Python to TXT Converter

Turn Python source code into a clean plain-text (.txt) file: optionally remove comments without touching strings, tidy whitespace, expand tabs and add line numbers for printing, sharing or uploading where code files are not accepted.
Runs in your browserLive result

Workspace

Options

Understands Python strings.

How to use this tool

  1. 1Open a .py file or paste Python code.
  2. 2Choose the clean-up options: comments, blank lines, tabs, line numbers.
  3. 3Check the result on the right.
  4. 4Download the .txt file.

Frequently asked questions

No. The comment remover reads Python strings properly, so text such as "http://…" or "/* … */" inside quotes is kept. Only real comments are removed, and lines that contained nothing but a comment disappear.

Yes. The #! line and the "# -*- coding: … -*-" declaration change how a script runs, so they are kept even when comments are removed. Docstrings are strings, not comments, and are kept too.

Many forms, learning platforms, email filters and chat tools reject code files but accept .txt. Plain text with line numbers is also easier to print, review or paste into a document.

LF works everywhere on macOS, Linux and the web. Choose CRLF only if the file will be opened in old Windows tools such as Notepad on Windows 7.

No. The conversion runs in your browser with JavaScript. Your file or pasted text is not uploaded, logged or stored by MuhammadLab.