473,661 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1600
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*******@gmai l.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\r eindent.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.__na me__

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.a r>
wrote:
>
Python already comes with a reindenter, see Tools\scripts\r eindent.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**********@g mail.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.__na me__

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
1798
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 example from page 90 of the mathml handbook, which is a simple bounded integral. The mathml is as follows, where I've substituted the numerical values for the named entities:- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE math SYSTEM...
10
2570
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 property set to 'Shop Number' in the table design. In the combo box though, I want to use 'Shop' as the heading (to save width) as shown in the SQL above. But the combo shows 'Shop Number' as a heading in form view.
8
1954
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
2516
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 fall between 1stday/anymonth/any year and 12thday/anymonth/any year are rearranged in the wrong format. For example 4th July 2005 from the database would be displayed as 07/05/2005 in the merged document. In addition blank date fields from the...
25
2692
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" long input lines into 2 or more shorter lines before the nth column... etc etc. Now, there are numerous anwers on the web and in the "C answer book", which includes a function to expand the tabs to blanks ( depending upon where the tab is in...
135
7445
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 which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the situation behind it, and which is proper.
1
3526
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 (.......) { statement ... }
6
3178
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
2092
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 editor wraps the code for me when I view it or work with it.
0
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8855
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8758
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.