title: Python - nested __repr__ reverts newline to "\\n"
body: <pre><code>class MyClass:
      def __init__(self):
          self.list_ = []
      def __repr__(self):
          return '\n'.join(['this','should','all','be','on','separate','lines']) + str([str(list_val) for list_val in self.list_])
  
  myClass = MyClass()
  myClass.list_.append(MyClass())
  myClass.list_[0].list_.append(MyClass())
  print(myClass)
  </code></pre>
  
  <p>I would expect this code to print:</p>
  
  <pre><code>this
  should
  all
  be
  on
  separate
  lines[this
  should
  all
  be
  on
  separate
  lines[this
  should
  all
  be
  on
  separate
  lines]]
  </code></pre>
  
  <p>or something similar, but instead it prints </p>
  
  <pre><code>this
  should
  all
  be
  on
  separate
  lines["this\nshould\nall\nbe\non\nseparate\nlines['this\\nshould\\nall\\nbe\\non\\nseparate\\nlines[]']"]
  </code></pre>
  
  <p>That is, when I try to convert an object to a string while already inside the <code>__repr__</code> method of another object of the same class, it turns a newline into <code>\n</code>, and if I nest it further it results in <code>\\n</code>, and each time I nest it it adds an additional backslash before the escape sequence.</p>
  
  <p>After reading <a href="https://stackoverflow.com/questions/24085680/why-do-backslashes-appear-twice">this question</a>, it seems that the <code>__repr__</code> method thinks I actually want the two characters <code>\</code> and <code>n</code>, but I don't: I want the escape sequence <code>\n</code>. Is there any way to override this and force it to interpret it as a newline rather than two separate characters?</p>