On 2020-06-17 12:46 p.m., Christopher Barker wrote:
On Wed, Jun 17, 2020 at 6:09 AM Soni L. <fakedme+py@gmail.com> wrote:
This also gives us two ways of doing indented strings (in Lua):

local ugly = "foo\n    \z
                  bar\n    \z
                  baz"
local nicer = "foo\n\z
               \x20   bar\n\z
               \x20   baz"

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.


or 

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

this is ugly. what's wrong with textwrap.dedent?

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.

  
-CHB
         


--
Christopher Barker, PhD

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