title: Get str repr with double quotes Python
body: <p>I'm using a small Python script to generate some binary data that will be used in a C header.</p>
  
  <p>This data should be declared as a <code>char[]</code>, and it will be nice if it could be encoded as a string (with the pertinent escape sequences when they are not in the range of ASCII printable chars) to keep the header more compact than with a decimal or hexadecimal array encoding.</p>
  
  <p>The problem is that when I print the <code>repr</code> of a Python string, it is delimited by single quotes, and C doesn't like that. The naive solution is to do:</p>
  
  <pre><code>'"%s"'%repr(data)[1:-1]
  </code></pre>
  
  <p>but that doesn't work when one of the bytes in the data happens to be a double quote, so I'd need them to be escaped too.</p>
  
  <p>I think a simple <code>replace('"', '\\"')</code> could do the job, but maybe there's a better, more pythonic solution out there.</p>
  
  <p><strong>Extra point</strong>:</p>
  
  <p>It would be convenient too to split the data in lines of approximately 80 characters, but again the simple approach of <a href="https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python">splitting the source string in chunks</a> of size 80 won't work, as each non printable character takes 2 or 3 characters in the escape sequence. Splitting the list in chunks of 80 <em>after</em> getting the repr won't help either, as it could divide escape sequence.</p>
  
  <p>Any suggestions?</p>