I've got two examples of code, that are supposed to perform the same thing (process text files and save the result to an outfile). However, this one doesn't work for me:
with codecs.open('outfile.txt', 'w', 'utf-8') as outfile:
for f in os.listdir(my_files):
outfile.write(some_function(codecs.open(f, 'r', 'utf-8')))
outfile.write('\n')
Whereas this works perfectly:
outfile = open('outfile.txt', 'w')
for f in os.listdir(my_files)
with open(f) as f_:
text = f_.read().decode('utf-8')
text = some_function(text)
outfile.write(text.encode('utf-8'))
outfile.write('\n')
Am I doing something wrong with python codecs? Thank you!