473,508 Members | 2,289 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 2702
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=utf-8 :

for i in xrange ( 3) :
print i

$ python2.5 PythonTidy.python < 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=utf-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=utf-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=utf-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=utf-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**********@upsn250.cri.u-psud.fr>, Laurent Pointal wrote:
Roberto Bonvallet a écrit :
># vim: set fileencoding=utf-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
1291
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...
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. ...
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...
0
916
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...
8
1484
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...
18
7157
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...
7
1784
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...
5
2064
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
1594
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...
0
7224
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
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
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
5626
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,...
1
5050
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...
0
4706
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...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
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 ...

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.