title: How to use python string split() on a backslash?
body: <p>I am trying to name a text file after the last directory in a file path.  I need to be able to get this name for OS's that use either forward or backward slashes. I've successfully used the string split() method for forward slash file paths but not backslash. Also, when I try to print the backslash directory name the slashes are not included (probably reading as escape sequences); however, when I use re.search() method it still finds the slash.</p>
  
  <p>How do I fix this?</p>
  
  <p>See code below:</p>
  
  <pre><code>import re
  import sys
  
  targetDirectory = sys.argv[1]
  filePathDirectorySeparator = ''
  usesForwardSlashSeparator = re.search('/', targetDirectory)
  if(usesForwardSlashSeparator):
      filePathDirectorySeparator = '/'
  else:
      filePathDirectorySeparator = '\\'
  
  fileName = targetDirectory.split(filePathDirectorySeparator)[-1]
  file = open(fileName, 'w+')
  file.write('HELLO')
  file.close()
  </code></pre>
  
  <p>The link shows my console output (I'm not allowed to embed images yet apparently...)</p>