title: Python, Windows, Ansi - encoding, again
body: <p><strong>Hello there,</strong></p>
  
  <p>even if i really tried... im stuck and somewhat desperate when it comes to <strong>Python</strong>, <strong>Windows</strong>, <strong>Ansi</strong> and <strong>character encoding</strong>. I need help, seriously... searching the web for the last few hours wasn't any help, it just drives me crazy.</p>
  
  <p>I'm new to Python, so i have almost no clue what's going on. I'm about to learn the language, so my first program, which ist <em>almost</em> done, should automatically generate music-playlists from a given folder containing mp3s. That works just fine, besides one single problem...</p>
  
  <p><strong>...i can't write Umlaute <em>(äöü)</em> to the playlist-file.</strong></p>
  
  <p>After i found a solution for <em>"wrong-encoded"</em> Data in the <code>sys.argv</code> i was able to deal with that. When reading Metadata from the MP3s, i'm using some sort of simple character substitution to get rid of all those international special chars, like french accents or this crazy skandinavian <em>"o"</em> with a slash in it <em>(i don't even know how to type it...)</em>. All fine.</p>
  
  <p>But i'd like to write at least the mentioned Umlaute to the playlist-file, those characters are really common here in Germany. And unlike the Metadata, where i don't care about some missing characters or miss-spelled words, this is relevant - because now i'm writing the paths to the files.</p>
  
  <p>I've tried so many various encoding and decoding methods, i can't list them all here.. heck, i'm not even able to tell which settings i tried half an hour ago. I found code online, here, and elsewhere, that seemed to work for some purposes. Not for mine. </p>
  
  <p>I think the tricky part is this: it seems like the Problem is the <strong>Ansi</strong> called format of the files i need to write. Correct - i actually need this Ansi-stuff. About two hours ago i actually managed to write whatever i'd like to an UFT-8 file. Works like charm... until i realized that my Player <em>(Winamp, old Version)</em> somehow doesn't work with those UTF-8 playlist files. It couldn't resolve the Path, even if it looks right in my editor. </p>
  
  <p>If i change the file format back to Ansi, Paths containing special chars get corrupted. I'm just guessing, but if Winamp reads this UTF-8 files as Ansi, that would cause the Problem i'm experiencing right now.</p>
  
  <p>So...</p>
  
  <ol>
  <li>I DO have to write äöü in a path, or it will not work</li>
  <li>It DOES have to be an ANSI-"encoded" file, or it will not work</li>
  <li>Things like <code>line.write(str.decode('utf-8'))</code> break the funktion of the file</li>
  <li>A magical comment at the beginning of the script like <code># -*- coding: iso-8859-1 -*-</code> does nothing here <em>(though it is helpful when it comes to the mentioned Metadata and allowed characters in it...)</em></li>
  <li>Oh, and i'm using Python 2.7.3. Third-Party modules dependencies, you know...</li>
  </ol>
  
  <p>Is there ANYONE who could guide me towards a way out of this encoding hell? Any help is welcome. If i need 500 lines of Code for another functions or classes, i'll type them. If there's a module for handling such stuff, let me know! I'd buy it! Anything helpful will be tested.</p>
  
  <p>Thank you for reading, thanks for any comment, </p>
  
  <p>greets!</p>