python compare words
Question: I have stuck with following problem: I am trying to get subject and compare
from email (it's saved on disk, email in UTF-8)

    
    
    import re
    
    def check_subj():
        subj = ""
        file = open("/home/hikaru/Desktop/sub.eml", "r")
    
        for line in file:
            try:
                a = re.search("Subject:\ ", line, re.IGNORECASE)
                a = line[a.end():]
                subj = a
                break
            except AttributeError:
                pass
        return subj
    
    print(check_subj())
    
    if check_subj() == 'sub':
        print("yay")
    

Everything seems fine to me, "print" successfully shows me "sub", but
comparison won't print "yay" for me. I can't understand why -(


Answer: An end of line, as suggested, is the probable cause of your problem. Here is a
more robust solution (the loop only)

    
    
    for line in file:
       match = re.search("Subject:\ (.*)", line, re.IGNORECASE)
       if match:
          subj = match.group(1)
          break
    

