Python and terminal - Strings with special characters
<p>I know the Python thing that if I'm using interactive interpreter and I write <code>'\\ '</code> it prints <code>'\\ '</code> but if if I write <code>print '\\ '</code> it prints <code>'\ '</code>.</p>

<p>What I'm trying to do is (in a script called <code>p.py</code>):</p>

<pre><code>import os
os.system('echo ' + 'string with spaces'.replace(' ', '\ '))
</code></pre>

<p>obviously it won't let me do this. I mean, Python manages to add TWO backslashes instead of one but I think it does so only in interactive mode, but the terminal, when passed special chars like <code>\</code>, ignores them.</p>

<p>So that, as the output of the provious code, I get:</p>

<pre><code>local:$ string with spaces
</code></pre>

<p>and not</p>

<pre><code>local:$ string\ with\ spaces 
</code></pre>

<p>I already tried hardcoded strings and everything else in Python, but I guess the problem is with shell strings.</p>

<p>How could I solve this?</p>

<p>It it can help to find alteratives solutions, what I'm trying to do is moving a file from python with the <code>mv</code> command, and this file has spaces in its name.</p>
