473,246 Members | 1,771 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,246 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 1584
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.