Source formatting fixer?

B

Bret

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
 
J

Jesse Jaggars

Bret said:
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
 
S

Steven D'Aprano

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.
 
B

Bret

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
 
G

Gabriel Genellina

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__
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top