Hexadecimal file is loading with 2 back slashes before each byte instead of one
<p>I have a hex file in this format: <code>\xda\xd8\xb8\x7d</code></p>

<p>When I load the file with Python, it loads with two back slashes instead of one.</p>

<pre><code>with open('shellcode.txt', 'r') as file:
    shellcode = file.read().replace('\n', '')
</code></pre>

<p>Like this: <code>\\xda\\xd8\\xb8\\x7d</code></p>

<p>I've tried using <code>hex.replace("\\", "\")</code>, but I'm getting an error</p>

<blockquote>
  <p>EOL while scanning string literal</p>
</blockquote>

<p>What is the proper way to replace <code>\\</code> with <code>\</code>?</p>

<p>Here is an example </p>

<pre><code>&gt;&gt;&gt; h = "\\x123"
&gt;&gt;&gt; h
'\\x123'
&gt;&gt;&gt; print h
\x123
&gt;&gt;&gt; 
</code></pre>

<p>The two backslashes are needed because \ is an escape character, and so it needs to be escaped.  When you print h, it shows what you want</p>

python escaping hex