title: how to access sys.argv (or any string variable) in raw mode?
body: <p>I'm having difficulties parsing filepaths sent as arguments:</p>
  
  <p>If I type:</p>
  
  <pre><code>os.path.normpath('D:\Data2\090925')
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>'D:\\Data2\x0090925'
  </code></pre>
  
  <p>Obviously the \0 in the folder name is upsetting the formatting. I can correct it with the following:</p>
  
  <pre><code>os.path.normpath(r'D:\Data2\090925')
  </code></pre>
  
  <p>which gives</p>
  
  <pre><code>'D:\\Data2\\090925'
  </code></pre>
  
  <p>My problem is, how do I achieve the same result with sys.argv? Namely:</p>
  
  <pre><code>os.path.normpath(sys.argv[1])
  </code></pre>
  
  <p>I can't find a way for feeding sys.argv in a raw mode into os.path.normpath() to avoid issues with folders starting with zero! </p>
  
  <p>Also, I'm aware that I could feed the script with <code>python script.py D:/Data2/090925</code> , and it would work perfectly, but unfortunately the windows system stubbornly supplies me with the '\', not the '/', so I really need to solve this issue instead of avoiding it.</p>
  
  <p><strong>UPDATE1</strong> to complement:
  if I use the script test.py: </p>
  
  <pre><code>import os, sys 
  if __name__ == '__main__': 
      print 'arg 1: ',sys.argv[1] 
      print 'arg 1 (normpath): ',os.path.normpath(sys.argv[1]) 
      print 'os.path.dirname :', os.path.dirname(os.path.normpath(sys.argv[1])) 
  </code></pre>
  
  <p>I get the following:</p>
  
  <pre><code>C:\Python&gt;python test.py D:\Data2\091002\ 
  arg 1: D:\Data2\091002\ 
  arg 1 (normpath): D:\Data2\091002 
  os.path.dirname : D:\Data2 
  </code></pre>
  
  <p>i.e.: I've lost 091002...</p>
  
  <p><strong>UPDATE2</strong>: as the comments below informed me, the problem is solved for the example I gave when normpath is removed:</p>
  
  <pre><code>import os, sys 
  if __name__ == '__main__': 
      print 'arg 1: ',sys.argv[1] 
      print 'os.path.dirname :', os.path.dirname(sys.argv[1])
      print 'os.path.split(sys.argv[1])):', os.path.split(sys.argv[1])
  </code></pre>
  
  <p>Which gives:</p>
  
  <pre><code> C:\Python&gt;python test.py D:\Data2\091002\ 
  arg 1: D:\Data2\091002\ 
  os.path.dirname : D:\Data2\091002
  os.path.split : ('D:\\Data2\\090925', '')
  </code></pre>
  
  <p>And if I use D:\Data2\091002 :</p>
  
  <pre><code> C:\Python&gt;python test.py D:\Data2\091002
  arg 1: D:\Data2\091002 
  os.path.dirname : D:\Data2
  os.path.split : ('D:\\Data2', '090925')
  </code></pre>
  
  <p>Which is something I can work with: Thanks!</p>