title: How to accept command-line args ending in backslash
body: <p>Here's a barebones Python app that simply prints the command-line arguments passed in:</p>
  
  <pre><code>import sys
  if __name__ == "__main__":
      print "Arguments:"
      for i in range(len(sys.argv)):
          print "[%s] = %s" % (i, sys.argv[i])
  </code></pre>
  
  <p>And here's some sample runs:</p>
  
  <pre><code>python args.py hello world
  Arguments:
  [0] = args.py
  [1] = hello
  [2] = world
  
  python args.py "hello world"
  Arguments:
  [0] = args.py
  [1] = hello world
  
  python args.py "hello\world"
  Arguments:
  [0] = args.py
  [1] = hello\world
  </code></pre>
  
  <p>So far so good. But now when I <em>end any argument with a backslash</em>, Python chokes on it:</p>
  
  <pre><code>python args.py "hello\world\"
  Arguments:
  [0] = args.py
  [1] = hello\world"
  
  python args.py "hello\" world "any cpu"
  Arguments:
  [0] = args.py
  [1] = hello" world any
  [2] = cpu
  </code></pre>
  
  <p>I'm aware of Python's less-than-ideal raw string behavior via the "r" prefix (<a href="https://stackoverflow.com/questions/647769/why-cant-pythons-raw-string-literals-end-with-a-single-backslash" title="Why can’t Python’s raw string literals end with a single backslash?">link</a>), and it seems clear that it's applying the same behavior here.</p>
  
  <p>But in this case, I don't have control of what arguments are passed to me, and I can't enforce that the arguments don't end in a backslash. How can I work around this frustrating limitation?</p>
  
  <p>--</p>
  
  <p><strong>Edit:</strong> Thanks to those who pointed out that this behavior isn't specific to Python. It seems to be standard shell behavior (at least on Windows, I don't have a Mac at the moment). </p>
  
  <p><strong>Updated question:</strong> How can I accept args ending in a backslash? For example, one of the arguments to my app is a file path. I can't enforce that the client sends it to me without a trailing backslash, or with the backslash escaped. Is this possible in any way?</p>