Passing indented code to compile()

Peter Hansen peter at engcorp.com
Wed May 7 10:22:39 EDT 2003


John Wilson wrote:
> 
> Peter Hansen wrote:
> > What you're faced with is, in effect, broken Python code.  Why not
> > just stop creating files with the bad/unnecessary indentation?
> >
> > (I assume this code is created manually, because if it was written
> > out by some automated process, the tool that did it is broken and
> > should be fixed.  It looks like it was written by hand, with aesthetics
> > in mind.  As Harvey points out, this kind of thing is not how XML
> > (or Python!) was intended to be used.
> 
> XML is intended to be human and machine readable. So we try hard to allow
> XML documents to be easily understood by humans as well as by machines. Most
> people find indentation in XML documents an aid to comprehension. The
> alignment of begin and end tags is particularly useful.

The "human readable" part is covered by the fact that XML documents
are text files, nothing more.  The XML goals never included "allow
arbitrary inclusion of arbitrary source code and support all rules
possibly used by arbitrary programming languages".

Anyway, if you're expecting people to generate these XML files *by hand*,
I guess you're stuck with ugly solutions to an awkward problem.  
Providing a tool that allows your users to type the Python code into
nice editing windows, avoiding the XML side of things, would be
a cleaner approach.

Finally, even outside of Python there are times when doing things like
"aligning begin and end tags" can cause trouble when using XML.  The
issues you are facing in large part are no solvable except by accepting
a slight reduction in readability.

By the way, there's nothing stopping you from always end with a newline,
and I believe even arbitrary white space after the last line, and you
can always start with a newline as well, so your example (snipped) is
largely a straw man argument...  only the mass-indentation is at issue,
and as long as you have a working solution, I guess you're back on track.

-Peter




More information about the Python-list mailing list