On Wed, Jun 17, 2020 at 8:58 AM Soni L. <fakedme+py@gmail.com> wrote:
I'm having a really hard time seeing why that is either more readable, or easier to type than:

nicest = ("foo"
          "   bar"
          "   baz"
          )
(my prefered way these days)

I think you missed some \n's here.

indeed I did:

nicest = ("foo\n"
          "   bar\n"
          "   baz\n"
          )
which I agree is not as nice, but still just as good as the proposal.

nicest = \
"""foo
   bar"
   baz"""

this is ugly.

I agree, and don't usually do that -- it depends a lot on the level of indentation I'm working in -- I would only do that at the top level.

> what's wrong with textwrap.dedent?

nothing -- but I left that out because it's a function call -- nothing to do with Python syntax, etc.

Though now that you mention is, I really dont like the \z idea -- I just don't see the point. But a simiple way to call (and pre-process detent  would be nice:

nicest = d"""foo
                bar
                baz"""

I  believe that's been proposed on this lists before -- not sure if it petered out, or was rejected.
 
however, I bring up again the original use-case which has nothing to do with textwrap.dedent, or nested indentation. But consider this artificial example:

foo = textwrap.dedent("""
    This is the help page for foo, a command \z
    with the following subcommands:
        bar - A very useful subcommand of foo \z
            and probably the subcommand you'll \z
            be using the most.
        baz - A simple maintenance command \z
            that you may need to use sometimes.
""")

Currently you'd have to write it as:

foo = (
    "This is the help page for foo, a command "
    "with the following subcommands:\n"
    "    bar - A very useful subcommand of foo "
    "and probably the subcommand you'll "
    "be using the most.\n"
    "    baz - A simple maintenance command "
    "that you may need to use sometimes."
)

or if you want it to look "nicer", and don't mind linters shouting at you:

foo = (
    "This is the help page for foo, a command "
    "with the following subcommands:\n"
    "    bar - A very useful subcommand of foo "
        "and probably the subcommand you'll "
        "be using the most.\n"
    "    baz - A simple maintenance command "
        "that you may need to use sometimes."
)

And I think this sucks.

less than ideal, yes -- but please post the \z version -- is it any better?

BTW, if I didn't mind linters yelling at me (and I don't), I'd do that as:

foo = (
    "This is the help page for foo, a command with the following subcommands:\n"
    "    bar - A very useful subcommand of foo and probably the subcommand you'll be using the most.\n"
    "    baz - A simple maintenance command that you may need to use sometimes."
)

Which does not suck as much.

And why that has nothing to do with textwrap.detent() I don't know -- that's pretty much EXACTLY what textwrap.detent() is for.

I'd also add that large blocks of text really don't belong inline as big literals -- if I had a use for that (and I do, for, e.g. help for command line programs) I"d put it somewhere else: either an external text file, or as literals at the tiop level of a module, where ordinary tripple quoted strings are easy:

FOO_HELP = """
This is the help page for foo, a command with the following subcommands:
    bar - A very useful subcommand of foo and probably the subcommand you'll be using the most.
    baz - A simple maintenance command that you may need to use sometimes.
"""

which is totally readable to me.

-CHB




--
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython