title: Python sys.argv auto-escaped my arguments from command line?
body: <p>I am trying to build a script needs the power from 'grep' in linux shell.<br />
  However, I found Python sys.argv escaped my regex pattern from command line.<br />
  For example, I am going to pass '\d' as grep pattern from command line.<br />
  But the string returned by sys.argv[1] was escaped as '\\d'</p>
  <p>I did the following test under debug mode:</p>
  <pre><code>#SyntaxTest.py
  import sys
    #other stuff preventing my debugger from stopping after importing
  
  #shell
  python3 -m pdb SyntaxTest.py '\d'
  
  &gt; /cygdrive/d/PythonSandBox/SyntaxTest.py(1)&lt;module&gt;()
  -&gt; import sys
  (Pdb) n
  (Pdb) sys.argv[1]
  '\\d'
  (Pdb) print(sys.argv[1])
  \d
  </code></pre>
  <p>I wonder why Python needs to escape my command line argument and I am asking a way to get a plain, un-escaped string in my example.</p>
  <h1>EDIT</h1>
  <p>It's impressive that '\\d'=='\d'.<br />
  But in my circumstance, I need to pass the string into subprocess like this.</p>
  <pre><code>&gt;&gt;&gt; pattern = '\d'
  &gt;&gt;&gt; str = r&quot;echo '%s'&quot;%pattern
  &gt;&gt;&gt; str
  &quot;echo '\\d'&quot;
  &gt;&gt;&gt; subprocess.check_output(str,shell=True)
  b'\\d\n'
  </code></pre>
  <p>It's obvious that \\d has been passed to shell. However, I need it to be just \d instead of \\d. Is there any way other than substitute manually?</p>