Hot #Python take: textwrap.dedent is great, but inspect.cleandoc is better (and it should be in textwrap, not inspect).
https://docs.python.org/3/library/inspect.html#inspect.cleandoc
(Actually not a hot take, it's carefully considered!)
Hot #Python take: textwrap.dedent is great, but inspect.cleandoc is better (and it should be in textwrap, not inspect).
https://docs.python.org/3/library/inspect.html#inspect.cleandoc
(Actually not a hot take, it's carefully considered!)
@nedbat Huh, I had no idea. I always do textwrap.dedent, then str.lstrip. This is much nicer, but seconding it should be in a more discoverable place!
@nedbat Never knew this existed, and never would have looked in `inspect` for this...
I think I can probably use it most everywhere I use `textwrap.dedent`, but tab expansion and different first-line handling give it slightly sharp edges.
@nedbat
I see that inspect.getdoc depends on inspect.cleandoc, so I guess it's to avoid a dependency on another package?
I'm the author of this popular StackOverflow answer https://stackoverflow.com/a/2504454/70157
and I approve Ned's message.