By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,048 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,048 IT Pros & Developers. It's quick & easy.

PythonTidy

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

[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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.