473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 1589
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jon Thackray | last post by:
I'm trying to build some mathml for a paper. I've got the mathml2 dtd, and the style sheets also from the canonical website http://www.w3.org/Math/. But I'm having some trouble. I've input the...
10
by: Bob Darlington | last post by:
I am using the following SQL as a RowSource for a combo box on a form. "SELECT LAN, TenantName as , ShopNum as FROM qTenantSelect " The field 'ShopNum' is a text field and has a caption...
8
by: Lauren Wilson | last post by:
I'd like to hear from anyone who has used any of the products from FMS at www.fmsinc.com. Just curious about your experience with these products.
7
by: Andy Davis | last post by:
I have a table of data in Access 2002 which is used as the source table for a mail merge document using Word 2002 on my clients PC. The data is transferred OK but I've noticed that any dates which...
25
by: mdh | last post by:
Hi Group, Not looking for an answer, but more of an explanation. Thinking back to those heady days when you had the time to do them, may I ask this. Exercise 1-22 asks for a program to "fold"...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
1
by: Sven Fischer | last post by:
After installation of Visual CSharp Studio the current settings of the source code editor are not suitable for me. The brackets are automaticlly set in front of the lines e.g. if (.......) {...
6
by: nicegirlflor | last post by:
Hello Members, Please, tell me best program to fix some problems with my PC,that working slowly,show me blue windows,some my programs not worked properly.How can I fix that problems? Thanks.
23
by: andrew | last post by:
Hi, I have been taken to task about the length of lines in the source html of: http://www.slrn.sourceforge.org which, as I commonly do, has no line breaks at all in the source html. My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.