File "POS_data.py", line 75, in <module> sys.exit(POScount_dict.main(sys.argv)) File "POS_data.py", line 59, in main self.count_tags(taggedtext) File "POS_data.py", line 39, in count_tags intext = open(taggedtext, 'r')TypeError: coercing to Unicode: need string or buffer, list found import sysimport reclass POS_data: """ Takes Part of Speech tagged data and puts the counts of tags into a dictionary """ def __init__(self): # Dictionary, keys are the tags, values are the counts of the tags self.POScount = {'.':0, 'NNP':0, ',':0, 'CD':0, 'NNS':0, 'JJ':0, 'MD':0, 'VB':0, 'DT':0, 'NN':0, 'IN':0, 'EOS':0, 'VBZ':0, 'VBG':0, 'CC':0, 'VBD':0, 'RB':0, 'TO':0, 'PRP':0, 'RBR':0, 'WDT':0, 'VBP':0, 'RP':0, 'PRP$':0, 'JJS':0, 'POS':0, '\'\'':0, 'EX':0, '``':0, 'WP':0, ':':0, 'JJR':0, 'WRB':0, '$':0, 'NNPS':0, 'WP$':0, '-LRB-':0, '-RRB-':0, 'PDT':0, 'RBS':0, 'FW':0, 'UH':0, 'SYM':0, 'LS':0, '#':0,} def count_tags(self, taggedtext): """ Counts all the tags in the text and updates the values of the tag keys in the dictionary """ intext = open(taggedtext, 'r', 'utf-8') lines = intext.readlines() intext.close() for line in lines: words = line.split(' ') for word in words: match = re.search('/.+$', word) if match: tag = match.group() tag_key = tag[1:] if self.POScount.has_key(tag_key): self.POScount[tag_key] = (self.POScount[tag_key] + 1) return def main(self, taggedtext): """ Count the Part of Speech tags of a tagged article and returns a dictionary with the tags and the counts """ self.count_tags(taggedtext) return self.POScountif __name__ == "__main__": """ This evaluates to true when this script is called from the comand-line. sys.exit calls your main function, which should know how to use your class in a way that also shows other people how your class ought to be used. If you want to use this class in another python script you write, add the directory to this script to the PYTHONPATH variable of your environment and use, e.g., from python_starter_file import myClass """ POScount_dict = POS_data() sys.exit(POScount_dict.main(sys.argv))