Search for Windows-1252 characters using Python
Question: I'm attempting to find, and subsequently replace a few Windows-1252 characters
with friendlier versions using Python. Specifically, I'd like to replace "µ"
and "³" but I can't even naively match the characters. For instance:

    
    
    with open(my_file) as f:
        for line in f:
            if "µ" in line:
                print "found"
    

The above does not work. However, the following does work within an
interpreter:

    
    
    line = "< 1.2 mg/dL(< 20 µmol/L) or N/A"
    if "µ" in line:
        print "found"
    

I've tried various uses of `decode` without success. Any help would be greatly
appreciated, thanks!

**edit**

Below are two lines of text from the file I'm walking over:

    
    
    < 1.2 mg/dL(< 20 µmol/L) or N/A
    1.2 - 1.9 mg/dL(20 - 32 µmol/L)
    


Answer: You need to open it in an encoding-aware way:

    
    
    import codecs
    
    with codecs.open(my_file, "r", "cp1252") as f:
        for line in f:
            if u"µ" in line:
                print "found"
    

