4 ms·
Use `textwrap.dedent()`?
by Spiritus 12y ago
Use `textwrap.dedent()`?
- mercurial 12y agoDidn't know about textwrap, but this does not strike me as particularly lightweight. You really want built-in syntax for something like this.
- noinsight 12y agoI normally just do this for multiline strings: s = "\n".join(["one","two","three"])
- philsnow 12y agoThis happens at run time whereas IIRC the string literal is crammed pre-joined into the ,pyc / .pyo file. The performance hit of doing this kind of thing really adds up in a larger app.
- stdbrouw 12y agoDedent is nice, but then you still have to deal with removing single newlines (e.g. for error messages) and removing leading and trailing spaces. Ultimately nothing more than `re.sub(r'[^\n]\n[^\n]', '', textwrap.dedent(s).strip())` but kind of annoying to have to throw this in your code all over the place.