Script that converts between indentation and curly braces in Python code

Beth McNany beth.mcnany at
Wed Jul 31 14:39:45 CEST 2013

from __future__ import braces ;)

ok, ok, if you *really* want it, you could keep track of how many leading
spaces there are (you are using spaces, right?), and insert an open bracket
where that number increases and a closing bracket where it decreases.  Of
course, as with all parsing problems, this is oversimplification... if you
have multi-line statements you'll need to check for those (if line starts
with """ or ''', ends with \, or if there's an unclosed bracket or
paren...) - but that'd be a reasonable place to start if you're only doing
short code snippets.

Also, I have to ask, how to you intend this to be used?  If there's no
indentation it will still be difficult to read, and your readers will then
have the problem of figuring out which curly braces to remove (for simple
code this might be easy, but for longer things you'd probably want an
automated way to re-indent, and a simple search-and-replace will screw up
any dictionaries, for instance).


On Tue, Jul 30, 2013 at 11:45 PM, Musical Notation <
musicdenotation at> wrote:

> Is there any script that converts indentation in Python code to curly
> braces? The indentation is sometime lost when I copy my code to an
> application or a website.
> --
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list