[Python-Dev] Triple-quoted strings and indentation (original) (raw)

Terry Reedy tjreedy at udel.edu
Wed Jul 6 07:59:51 CEST 2005


"Andrew Durdin" <adurdin at gmail.com> wrote in message news:59e9fd3a0507052116307e4d84 at mail.gmail.com...

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

At present I think I would do usage_text = '''
text how I want it ''' perhaps in global context or at top of function and then

try: options, args = getopt.getopt(sys.argv[1:], "cf:s") except getopt.GetoptError: print usage_text

I long ago found it advantageous to pull message texts from scattered locations into a central place where easier to find and edit. I also make program logic easier to read without a long block in the way. YMMV Doc strings, first meant for the code reader, need to be where they are. They also come before the code itself, so don't interfere.

-- it's a wart:

That is rather extreme, and is definitely an opinion.

I have written a patch that changes the way triple-quoted strings are scanned so that leading whitespace is ignored.

And what if I want the leading whitespace left just the way I carefully put it? And what of existing code dependent on literals being as literal as they currently are? I think the soonest this could be considered is Python 3.0.

Terry J. Reedy



More information about the Python-Dev mailing list