Script that converts between indentation and curly braces in Python code

Beth McNany beth.mcnany at gmail.com
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).

-beth

On Tue, Jul 30, 2013 at 11:45 PM, Musical Notation <
musicdenotation at gmail.com> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130731/e50dee27/attachment.html>


More information about the Python-list mailing list