[Python-Dev] Triple-quoted strings and indentation

Andrew Durdin adurdin at gmail.com
Wed Jul 6 06:16:59 CEST 2005


In general, I find triple-quoted strings to be very handy,
particularly for standalone scripts. However, the fact that they have
to be written in the left-hand column to avoid leading whitespace
really grates, particularly when they're nested within a block or two
-- it's a wart:
 try:
 options, args = getopt.getopt(sys.argv[1:], "cf:s")
 except getopt.GetoptError:
 print """Usage: dostuff <options>
Options:
 -c - blah blah
 -f <filename> - do stuff with file "filename"
 -s - more blah"""
 sys.exit(1)
This really makes the code hard to read, as the indentation is all
mixed up (visually).
I have written a patch that changes the way triple-quoted strings are
scanned so that leading whitespace is ignored in much the same way
that pep 257 handles it for docstrings. Largely this was for a
learning experience in hacking the parser, but it would be very nice
IMO if something of this sort could be implemented in a future version
of Python. To this end, I have sketched out a draft PEP (which was
itself a good learning exercise in thinking out the issues of such a
change). Should I post it here for discussion?
Andrew


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /