I'm doing a python script to organize and count words from a text given by a file. I have the problem when printing it to another file.
The code that prints the file is this:
def printToFile(self, fileName):
file_to_print = open(fileName, 'w')
file_to_print.write(str(self))
file_to_print.close()
and here the str of the class called in my other method:
def __str__(self):
cadena = ""
for key in self.processedWords:
cadena += str(key) + ": " + str(self.processedWords[key]) + "\n"
return cadena.decode('string_escape')
The issue is that if I print it through the console there are no errors, the problem comes when you print it in the file that appear as follows: