endcoding error
<p>my code has a trouble with encoding error:</p>

<p>File "test.py", line 1</p>

<p>SyntaxError: encoding problem: with BOM</p>

<p>I attached the code below. is there any clear idea to fix it? the input and the output file contain Korean words, numbers, and english charaters.</p>

<p>I try to run this code in Mac and windows, it doesn't work at both of OS. please help me out!</p>

<pre><code># coding: uft-8

from __future__ import print_function
from __future__ import unicode_literals
import os, sys
import codecs
import re
import subprocess, shlex


REGEXP = re.compile(r'(\w+)/(\(.*?\))')                                                                                                                                                                                                                                 


def main():                                                                                                                                                                                                                                                             
    words = {}                                                                                                                                                                                                                                                          

    with codecs.open('E:\\mach.txt', 'r', encoding='cp949') as fp: 
        for line in fp:                                                                                                                                                                                                                                                     
            for item, category in REGEXP.findall(line):                                                                                                                                                                                                                     
                words.setdefault(category, {}).setdefault(item, 0)                                                                                                                                                                                                          
                words[category][item] += 1                                                                                                                                                                                                                                  

    with codecs.open('result.txt', 'w', encoding='cp949') as fp:                                                                                                                                                                                                                                        
        for category, words in sorted(words.items()):                                                                                                                                                                                                                       
            print(category, file=fp)                                                                                                                                                                                                                                        
            for word, count in words.items():                                                                                                                                                                                                                               
                print(word, count, sep=' ', file=fp)                                                                                                                                                                                                                        
            print(file=fp)                                                                                                                                                                                                                                                  
    return 0                                                                                                                                                                                                                                                            

if __name__ == '__main__':                                                                                                                                                                                                                                              
    raise SystemExit(main()) 
</code></pre>
