automated pep8 reformatter ?

J

James Mills

Does anyone know of a tool that will help with
reformatting badly written code to be pep8 compliant ?

a 2to3 for pep8 ?

cheers
James
 
J

James Mills

A step forward might be the ‘reindent.py’ program included with the
Python distribution.

I have tried to use this tool - but it lacks certain features.

Maybe I could use this as a starting point in writing such a tool :)

What I really want is to fix up common "poor" (IHMO) coding styles
in code that I have to maintain/review/etc. Things like:
* Lines longer than 80 characters
* Comments tacked on to the end of statements/expressions
* Use of ' vs. "
* More liberal use of Whitespace

Why ? Simple. Being vision impaired (in fact legally blind of <1% sight)
I find it hard to read and maintain code that exhibits poor coding style
(especially the above). -- It is of course very personal and very subjective.
(But hey maybe I should write a tool anyway!)
Many PEP 8 violations can't be automatically fixed, they require the
programmer to make a decision and edit the code. So first, introduce a
code scanner that reports PEP 8 violations, such as ‘pylint’.

As stated, I'm not overly concerned with problems that a more sophisticated
static code analyzer such a pylint might find - I'm more interested in
readability more than anything. I often use pyflakes in conjunction with
pep8 to keep my own code clean, readable and consistent.

Thanks for the suggestion!

cheers
James
 
J

James Mills

Most of those don't have sensible automated responses. There aren't good
automatic answers to “where should this line of code be broken tofit
within 80 columns?†or “where should this end-line comment go instead?â€.

And of course you are quite right. But it doesn't hurt to ask :)
If you come up with algorithmic answers to all the above problems, yes,
you could write such a tool. But I doubt it would be generally
applicable; and consequently, I doubt that a generally-applicable tool
already exists that fits your tastes.

I doubt such a tool could be written either.

The vim plugin I referenced earlier works nicely enough.

cheers
James
 

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,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top