日々精進

新しく学んだことを書き留めていきます

pythonでヒアドキュメントを書きたい

qiita.com

が参考になりました。 以下のように書くとインデントと前後の改行を無視してくれる。 もっとすんなり書ければいいけど。。

import textwrap
string = textwrap.dedent('''
  This is a {what}.
  I'm from {where}.
''').format(what="apple", where="Chiba").strip()