PythonTidy

Chuck Rhode CRhode at LacusVeris.com
Thu Nov 30 21:52:40 EST 2006


Thomas Heller wrote this on Thu, Nov 30, 2006 at 09:50:25PM +0100.  My
reply is below.

> The two things that bother me at the moment are how the comments are
> formatted (dunno if that can be customized or changed easily), and
> it would be good if the script took command line args instead of
> working as a filter only.

Thank you for trying PythonTidy.

o Command-line args: Please give an example of a standard command that
I might emulate w.r.t. standard argument use.

o Comments: Input is parsed twice: I use *tokenize.generate_tokens* to
extract the comments and *compiler.parse* to generate the Abstract
Syntax Tree (AST).  Other applications usually use the AST to generate
bytecode, so it contains no information about comments.  The tokens
list identifies keywords (and comments and some whitespace) but
doesn't group them into statements.  I need both: comments *and*
functional grouping.  Fortunately both the AST and the tokens list
carry line numbers to reference the source.  Unfortunately the AST
line numbers are relative to functional groups and do not necessarily
apply to the particular keywords that introduce each group.  This
makes fixing the position of comments relative to reconstructed code a
bit of a challenge.  For example, when a comment has a line number in
the beginning/ending range of what would normally be considered one
command, I have to assume it is an inline comment regardless of how it
may have appeared in the original code.

Out-of-line comments should appear pretty much as they did in the
original code, however.  Can you provide an example where they do not?
Would you prefer that they be left justified or wrapped?  >-~

Doc strings (for modules, class declarations, and functions) are
another matter.  PythonTidy should not mess with them (unless
LEFTJUST_DOC_STRINGS is True).  They should appear exactly as
originally written.

I was taught that code ought to be self documenting and that comments
more often than not diminish readability by padding the code beyond
what can be comprehended on one page (screen).  I use them only
minimally and am not greatly inconvenienced when they are moved around
a little.

-- 
.. Chuck Rhode, Sheboygan, WI, USA
.. Weather:  http://LacusVeris.com/WX
.. 21° — Wind N 8 mph



More information about the Python-list mailing list