471,355 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

Source formatting fixer?

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
Dec 10 '07 #1
5 1532
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
Dec 11 '07 #2
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.
Dec 11 '07 #3
En Tue, 11 Dec 2007 12:22:11 -0300, Jesse Jaggars <jh*******@gmail.com>
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

Dec 11 '07 #4
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" <gagsl-...@yahoo.com.ar>
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
Dec 14 '07 #5
En Fri, 14 Dec 2007 15:33:44 -0300, Bret <br**********@gmail.comescribió:
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

Dec 14 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jon Thackray | last post: by
10 posts views Thread by Bob Darlington | last post: by
25 posts views Thread by mdh | last post: by
135 posts views Thread by Xah Lee | last post: by
23 posts views Thread by andrew | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.