My program produces the desired results correctly as I print them on the screen using the print()
function:
for k in main_dic.keys():
s = 0
print ('stem:', k)
print ('word forms and frequencies:')
for w in main_dic[k]:
print ('%-10s ==> %10d' % (w,word_forms[w]))
s += word_forms[w]
print ('stem total frequency:', s)
print ('------------------------------')
I want to write the results with the exact format to a text file though. I tried with this:
file = codecs.open('result.txt','a','utf-8')
for k in main_dic.keys():
file.write('stem:', k)
file.write('\n')
file.write('word forms and frequencies:\n')
for w in main_dic[k]:
file.write('%-10s ==> %10d' % (w,word_forms[w]))
file.write('\n')
s += word_forms[w]
file.write('stem total frequency:', s)
file.write('\n')
file.write('------------------------------\n')
file.close()
but I get the error:
TypeError: write() takes 2 positional arguments but 3 were given