title: Python findall, regex, unicode
body: <p>I'm trying to write a Python script that searches thru a directory tree and lists all .flac files and derives Arist, Album and Title from resp. dir/subdir/filename and write that to a file. The code works fine, until it hits a unicode character. Here's the code:</p>
  
  <pre><code>import os, glob, re
  
  def scandirs(path):
      for currentFile in glob.glob(os.path.join(path, '*')):
      if os.path.isdir(currentFile):
          scandirs(currentFile)
      if os.path.splitext(currentFile)[1] == ".flac":
          rpath = os.path.relpath(currentFile)
          print "**DEBUG** rpath =", rpath
          title = os.path.basename(currentFile)
          title = re.findall(u'\d\d\s(.*).flac', title, re.U)
          title = title[0].decode("utf8")
          print "**DEBUG** title =", title
          fpath = os.path.split(os.path.dirname(currentFile))
          artist = fpath[0][2:]
          print "**DEBUG** artist =", artist
          album = fpath[1]
          print "**DEBUG** album =", album
          out = "%s | %s | %s | %s\n" % (rpath, artist, album, title)
          flist = open('filelist.tmp', 'a')
          flist.write(out)
          flist.close()
  
  scandirs('./')
  </code></pre>
  
  <p>code output:</p>
  
  <pre><code>**DEBUG** rpath = Thriftworks/Fader/Thriftworks - Fader - 01 180°.flac
  **DEBUG** title = 180°
  **DEBUG** artist = Thriftworks
  **DEBUG** album = Fader
  Traceback (most recent call last):
    File "decflac.py", line 25, in &lt;module&gt;
      scandirs('./')
    File "decflac.py", line 7, in scandirs
      scandirs(currentFile)
    File "decflac.py", line 7, in scandirs
      scandirs(currentFile)
    File "decflac.py", line 20, in scandirs
      out = "%s | %s | %s | %s\n" % (rpath, artist, album, title)
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 46: ordinal not in range(128)
  </code></pre>
  
  <p>But when tried in Python console, it is working fine:</p>
  
  <pre><code>&gt;&gt;&gt; import re
  &gt;&gt;&gt; title = "Thriftworks - Fader - 01 180°.flac"
  &gt;&gt;&gt; title2 = "dummy"
  &gt;&gt;&gt; title = re.findall(u'\d\d\s(.*).flac', title, re.U)
  &gt;&gt;&gt; title = title[0].decode("utf8")
  &gt;&gt;&gt; out = "%s | %s\n" % (title2, title)
  &gt;&gt;&gt; print out
  dummy | 180°
  </code></pre>
  
  <p>So, my questions:
  1) How come the same code works in the console, but not in the script?
  2) How to fix the script?</p>