title: Python - Can (or should) I change os.path.sep?
body: <p>I am writing a script to parse multiple log files and maintain a list of the files that have been processed. When I read the list of files to process I use <code>os.walk</code> and get names similar to the following:</p>
  
  <pre><code>C:/Users/Python/Documents/Logs\ServerUI04\SystemOut_13.01.01_20.22.25.log
  </code></pre>
  
  <p>This is created by the following code:</p>
  
  <pre><code>filesToProcess.extend(os.path.join(root, filename) for filename in filenames if logFilePatternMatch.match(filename))
  </code></pre>
  
  <p>It appears that "root" used forward slashes as the separator (I am on Windows and find that more convenient) but "filename" uses backslashes so I end up with an inconsistent path for the file as it contains a mixture of forward and back slashes as separators.</p>
  
  <p>I have tried setting the separator with:</p>
  
  <pre><code>os.path.sep = "/"
  </code></pre>
  
  <p>and</p>
  
  <pre><code>os.sep = "/"
  </code></pre>
  
  <p>Before the .join but it seems to have no effect. I realize that in theory I could manipulate the string but longer term I'd like my script to run on Unix as well as Windows so would prefer that it be dynamic if possible.</p>
  
  <p>Am I missing something?</p>
  
  <p>Update:</p>
  
  <p>Based on the helpful responses below it looks like my problem was self inflicted, for convenience I had set the initial path used as root like this:</p>
  
  <pre><code>logFileFolder = ['C:/Users/Python/Documents/Logs']
  </code></pre>
  
  <p>When I changed it to this:</p>
  
  <pre><code>logFileFolder = ['C:\\Users\\Python\\Documents\\Logs']
  </code></pre>
  
  <p>Everything works and my resulting file paths all use the "\" throughout. It looks like my approach was wrong in that I was trying to get Python to change behavior rather than correcting what I was setting as a value.</p>
  
  <p>Thank you!</p>