def _search_coding_line(txt):
 coding_pattern = u'coding[:=]\\s*([-\\w.]+)'
 pat_coding = re.search(coding_pattern, txt)
 if (pat_coding and (pat_coding.groups()[0] != u'None')):
  return pat_coding.groups()[0]
 return None

def _search_coding_line ( txt ) : coding_pattern = u'coding[:=]\\s*([-\\w.]+)' pat_coding = re . search ( coding_pattern , txt ) if ( pat_coding and ( pat_coding . groups ( ) [ 0 ] != u'None' ) ) : return pat_coding . groups ( ) [ 0 ] return None
search a pattern like this: # -*- coding: utf-8 -*- .