Source formatting fixer?

Discussion in 'Python' started by Bret, Dec 10, 2007.

  1. Bret

    Bret Guest

    Does anyone know of a package that can be used to "fix" bad formatting
    in Python code? I don't mean actual errors, just instances where
    someone did things that violate the style guide and render the code
    harder to read.

    If nothing exists, I'll start working on some sed scripts or something
    to add spaces back in but I'm hoping someone out there has already
    done something like this.

    Thanks!


    Bret Wortman
    Bret, Dec 10, 2007
    #1
    1. Advertising

  2. Bret wrote:
    > Does anyone know of a package that can be used to "fix" bad formatting
    > in Python code? I don't mean actual errors, just instances where
    > someone did things that violate the style guide and render the code
    > harder to read.
    >
    > If nothing exists, I'll start working on some sed scripts or something
    > to add spaces back in but I'm hoping someone out there has already
    > done something like this.
    >
    > Thanks!
    >
    >
    > Bret Wortman
    >

    This may not be exactly what you want, but if you use Gedit there is a
    handy reindent plugin.


    http://live.gnome.org/Gedit/Plugins/Reindent
    Jesse Jaggars, Dec 11, 2007
    #2
    1. Advertising

  3. On Mon, 10 Dec 2007 13:55:15 -0800, Bret wrote:

    > Does anyone know of a package that can be used to "fix" bad formatting
    > in Python code? I don't mean actual errors, just instances where
    > someone did things that violate the style guide and render the code
    > harder to read.
    >
    > If nothing exists, I'll start working on some sed scripts


    sed???

    Python has a range of tools for processing Python source code, which is
    probably a far better solution than processing it as raw text.

    --
    Steven.
    Steven D'Aprano, Dec 11, 2007
    #3
  4. En Tue, 11 Dec 2007 12:22:11 -0300, Jesse Jaggars <>
    escribi�:

    > Bret wrote:
    >> Does anyone know of a package that can be used to "fix" bad formatting
    >> in Python code? I don't mean actual errors, just instances where
    >> someone did things that violate the style guide and render the code
    >> harder to read.
    >>

    > This may not be exactly what you want, but if you use Gedit there is a
    > handy reindent plugin.
    >
    > http://live.gnome.org/Gedit/Plugins/Reindent


    Python already comes with a reindenter, see Tools\scripts\reindent.py
    If you want to transform y= f ( x- 3 ) into y = f(x - 3) try PythonTidy
    (search this same group for a link)

    --
    Gabriel Genellina
    Gabriel Genellina, Dec 11, 2007
    #4
  5. Bret

    Bret Guest

    The thing is, I'm not so much trying to fix indentation issues as
    spacing problems that affect readability but not program structure.
    All the indentation is fine, this is more trying to change things
    like:

    if ((one==two)and(three==four)):
    a=b+42
    c=Classname (a,b)
    print "Class %s created"%c.__name__

    None of the above is wrong, it's just painfully ugly and given
    Python's natural beauty, it seems really wrong all the same....


    Bret

    On Dec 11, 3:26 pm, "Gabriel Genellina" <>
    wrote:
    >
    > Python already comes with a reindenter, see Tools\scripts\reindent.py
    > If you want to transform y= f ( x- 3 ) into y = f(x - 3) try PythonTidy
    > (search this same group for a link)
    >
    > --
    > Gabriel Genellina
    Bret, Dec 14, 2007
    #5
  6. En Fri, 14 Dec 2007 15:33:44 -0300, Bret <> escribió:

    > The thing is, I'm not so much trying to fix indentation issues as
    > spacing problems that affect readability but not program structure.
    > All the indentation is fine, this is more trying to change things
    > like:
    >
    > if ((one==two)and(three==four)):
    > a=b+42
    > c=Classname (a,b)
    > print "Class %s created"%c.__name__
    >
    > None of the above is wrong, it's just painfully ugly and given
    > Python's natural beauty, it seems really wrong all the same....


    PythonTidy http://pypi.python.org/pypi/PythonTidy may help, altough I feel
    it too aggressive sometimes.
    Your example above is converted into this:

    #!/usr/bin/python
    # -*- coding: utf-8 -*-

    if one == two and three == four:
    a = b + 42
    c = Classname(a, b)
    print 'Class %s created' % c.__name__

    --
    Gabriel Genellina
    Gabriel Genellina, Dec 14, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. just say NO to PDF

    Formatting HTML Source - Is there a utility?

    just say NO to PDF, Jul 17, 2003, in forum: HTML
    Replies:
    23
    Views:
    890
    Brian
    Oct 16, 2003
  2. dorayme
    Replies:
    6
    Views:
    425
    dorayme
    Nov 28, 2006
  3. Replies:
    3
    Views:
    596
  4. tvn
    Replies:
    5
    Views:
    688
    Stephen Sprunk
    Apr 5, 2010
  5. Fair Loophole

    Fast Fixer-Upper Profits

    Fair Loophole, Jun 5, 2008, in forum: Javascript
    Replies:
    0
    Views:
    90
    Fair Loophole
    Jun 5, 2008
Loading...

Share This Page