I have the following code for parsing some HTML. I need to save the output (html result) as a single line of code with the escaped character sequences there such as `\n` but I'm either getting a representation I can't use from `repr()` because of the single quotes or the output is being written to multiple lines like so (interpreting the escape sequences):

```
<section class="prog__container">
 <span class="prog__sub">Title</span>
 <p>PEP 336 - Make None Callable</p>
 <span class="prog__sub">Description</span>
 <p>
 <p>
 <code>
      None
     </code>
     should be a callable object that when called with any
 arguments has no side effect and returns
     <code>
      None
     </code>
     .
    </p>
 </p>
 </section>

```

What I require (including the escape sequences):

```
<section class="prog__container">\n <span class="prog__sub">Title</span>\n <p>PEP 336 - Make None Callable</p>\n <span class="prog__sub">Description</span>\n <p>\n <p>\n <code>\n      None\n     </code>\n     should be a callable object that when called with any\n arguments has no side effect and returns\n     <code>\n      None\n     </code>\n     .\n    </p>\n </p>\n </section>

```

**My Code**

```
soup = BeautifulSoup(html, "html.parser")

for match in soup.findAll(['div']):
    match.unwrap()

for match in soup.findAll(['a']):
    match.unwrap()

html = soup.contents[0]
html = str(html)
html = html.splitlines(True)
html = " ".join(html)
html = re.sub(re.compile("\n"), "\\n", html)
html = repl(html) # my current solution works, but unusable

```

The above is my solution, but an object representation is no good, I need the string representation. How can I achieve this?