473,569 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PythonTidy

I couldn't find a routine to clean up, regularize, and reformat Python
code, so I wrote one:

http://www.lacusveris.com/PythonTidy/PythonTidy.python

Now, I'm looking for beta-testers. Compensation is a bit on the low
side. In fact it's limited to the satisfaction of helping out.
Thanks.

--
... Chuck Rhode, Sheboygan, WI, USA
Nov 30 '06 #1
8 2708
Chuck Rhode wrote:
I couldn't find a routine to clean up, regularize, and reformat Python
code, so I wrote one:

http://www.lacusveris.com/PythonTidy/PythonTidy.python

Now, I'm looking for beta-testers. Compensation is a bit on the low
side. In fact it's limited to the satisfaction of helping out.
$ cat test.py
#!/usr/bin/env python2.5
# vim: set fileencoding=ut f-8 :

for i in xrange ( 3) :
print i

$ python2.5 PythonTidy.pyth on < test.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

for i in xrange(3):
print i

About changing the shebang line: I'll take it as a bug.
About changing the encoding declaration from vim-style to emacs-style:
I'll take it as an insult :)

Both are comments, and should be left that way. Besides, there is no
officially preferred way for each of them. BTW, in a recent thread on
this newsgroup, most people said they preferred #!/usr/bin/env python over
#!/usb/bin/python for the shebang line. See http://tinyurl.com/yngmfr .

Best regards.
--
Roberto Bonvallet
Nov 30 '06 #2
Roberto Bonvallet a écrit :
Chuck Rhode wrote:
>I couldn't find a routine to clean up, regularize, and reformat Python
code, so I wrote one:

http://www.lacusveris.com/PythonTidy/PythonTidy.python

Now, I'm looking for beta-testers. Compensation is a bit on the low
side. In fact it's limited to the satisfaction of helping out.
....
# vim: set fileencoding=ut f-8 :
....
# -*- coding: utf-8 -*-
....
About changing the shebang line: I'll take it as a bug.
About changing the encoding declaration from vim-style to emacs-style:
I'll take it as an insult :)
This is not "emacs-style", this is Python normalized source encoding
directive for correct interpretation of u"..." strings by Python
interpreter.

See http://www.python.org/dev/peps/pep-0263/
A+

Laurent.
Nov 30 '06 #3
Laurent Pointal wrote:
...
># vim: set fileencoding=ut f-8 :
...
># -*- coding: utf-8 -*-
...

This is not "emacs-style", this is Python normalized source encoding
directive for correct interpretation of u"..." strings by Python
interpreter.

See http://www.python.org/dev/peps/pep-0263/
The -*- syntax is emacs-style. The encoding directive is anything that
matches r"coding[=:]\s*([-\w.]+)". The docs recommend to use either
emacs-style or vim-style. See http://docs.python.org/ref/encodings.html

Cheers,
--
Roberto Bonvallet
Nov 30 '06 #4

[Roberto]
# vim: set fileencoding=ut f-8 :
...
# -*- coding: utf-8 -*-
...
About changing the encoding declaration from vim-style to emacs-style:
I'll take it as an insult :)
[Laurent]
This is not "emacs-style", this is Python normalized source encoding
directive for correct interpretation of u"..." strings by Python
interpreter.
So is "# vim: set fileencoding=ut f-8". Anything matching
"coding[:=]\s*([-\w.]+)" on the first or second line counts.
See http://www.python.org/dev/peps/pep-0263/
Yes, you should. 8-)

--
Richie Hindle
ri****@entrian. com
Nov 30 '06 #5
In <ek**********@u psn250.cri.u-psud.fr>, Laurent Pointal wrote:
Roberto Bonvallet a écrit :
># vim: set fileencoding=ut f-8 :
...
># -*- coding: utf-8 -*-
...
>About changing the shebang line: I'll take it as a bug.
About changing the encoding declaration from vim-style to emacs-style:
I'll take it as an insult :)

This is not "emacs-style", this is Python normalized source encoding
directive for correct interpretation of u"..." strings by Python
interpreter.

See http://www.python.org/dev/peps/pep-0263/
Where does it say it has to be emacs-style? It just uses that style as
example as far as I can see. The real definition is a regexp:

coding[:=]\s*([-\w.]+)

So the vim-style is fine. No need to replace it.

Ciao,
Marc 'BlackJack' Rintsch
Nov 30 '06 #6
Laurent Pointal a écrit :
See http://www.python.org/dev/peps/pep-0263/
Aye, sorry for my missreading...

[seem I hurt the emacs guy]

Nov 30 '06 #7
Roberto Bonvallet wrote this on Thu, Nov 30, 2006 at 01:21:55PM +0000. My reply is below.
About changing the shebang line: I'll take it as a bug.
About changing the encoding declaration from vim-style to
emacs-style: I'll take it as an insult :)
Ooh! <wounded>
Both are comments, and should be left that way. Besides, there is no
officially preferred way for each of them. BTW, in a recent thread on
this newsgroup, most people said they preferred #!/usr/bin/env python over
#!/usb/bin/python for the shebang line. See http://tinyurl.com/yngmfr .
Thanks for the link. I was unaware of the /usr/bin/env technique and
the controversy surrounding it.

Thanks, too, for trying *PythonTidy*.

As you have no doubt perceived, *PythonTidy* is *not* "table driven."
It is a script after all. I decided before writing it that I didn't
really need to externalize all the options; nevertheless, most are
declared near the beginning where they sit just begging for end-user
involvement. See: CODING_SPEC and SHEBANG. *PythonTidy* is all about
consistency, consistency, and consistency. You can use it to
standardize shebangs and coding across a whole library of Python
scripts.

--
... Chuck Rhode, Sheboygan, WI, USA
... Weather: http://LacusVeris.com/WX
... 25° — Wind NW 13 mph
Nov 30 '06 #8
Chuck Rhode wrote:
[...]
Thanks, too, for trying *PythonTidy*.
No, thanks you for writing such a tool!
[...] nevertheless, most [options] are declared near the beginning where
they sit just begging for end-user involvement. See: CODING_SPEC and
SHEBANG.
The fact that I immediately noticed them and came up with an example to
raise both issues is a indicator of how easy it would be to customize the
script :)

Cheers!
--
Roberto Bonvallet
Nov 30 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1295
by: Paul Boddie | last post by:
QOTW: "We of all people should understand Worse Is Better. And I forgot to mention a little flash in the pan called Python, for which Tkinter (2+2 left as an exercise) is the GUI of choice." - Ken Tilton (on comp.lang.lisp, perhaps stretching the meaning of "of choice" somewhat)...
2
303
by: Chuck Rhode | last post by:
That went well. PythonTidy has been looked at at least 10**2 times, and I have received a couple of complaints, which I hope I have addressed satisfactorily -- plenty good enough for a beta test. The basic concept stands. PythonTidy.py cleans up, regularizes, and reformats the text of Python scripts: ...
9
3751
by: siggi | last post by:
Hi all, as a newbie I have problems with formatting code of downloaded programs, because IDLE's reformatting capabilities are limited . Incorrect indentation, mixing of TAB with BLANKs or eol are often very nasty to correct. Is there a simple code formatter that first removes all indentations and then refomats correctly? Please help!
0
918
by: Chuck Rhode | last post by:
PythonTidy cleans up, regularizes, and reformats the text of Python scripts. It is released under the GNU General Public License. Python scripts are usually so good looking that no beautification is required. However, from time to time, it may be necessary to alter the style to conform to changing standards. This script converts...
8
1492
by: Vincent Delporte | last post by:
Hello When I copy/paste Python code from the web, every so often, the TABs are wrong, which means that the code won't work and I have to manually reformat the code. Is there a code reformater that can parse the code to make it right? Thanks.
18
7160
by: Franz Steinhaeusler | last post by:
Hello, I did not find any reasonable pyhton source code beautifier program (preferable gui). Some would ask why? Program it immediatly good. (BTW: Would be a nice project, if I would have more spare time). Ich have some foreign source, which are programed in a way I don't like, so I would like to have a tool, which automatically...
7
1790
by: montyphyton | last post by:
Some recent posts about Python programming style got me thinking. Since we have the PEP 8 which gives some guidelines about the style to be used, do we have any program that can check for violations of these guidelines within the source code? I understand that there are a lot of code beautifiers out there, but i haven't seen one specially...
5
2071
by: David | last post by:
All, Is there a pretty printing utility for Python, something like Tidy for HTML? That will change: xp=self.uleft+percentx*(self.xwidth) To:
5
1596
by: Bret | last post by:
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...
0
7703
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7930
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. ...
0
8138
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...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6290
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
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...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
950
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...

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.