I'm trying to open and read a file, split the contents into words, and then iterate through them and remove all the punctuation. Why is this returning a
TypeError: expected a character buffer object and how can I fix it?
with open(self.filename, "r") as file_opened: text = file_opened.read() words_with_punct = text.split() remove = dict.fromkeys(map(ord, '\n' + string.punctuation)) for i in words_with_punct: words = i.translate(remove) return words
text = file_opened.read().translate(None,string.punctuation)
should work fine not sure what all the other stuff your doing is supposed to do