text = open('text.txt', 'r') # open the txt file lines = text.readlines() # to divide the text into lines lines_noempty = [ ] x = 1 new_html = open('annotated-reader.html', 'a+') for line in lines: if line is not "\n": # if line is not empty, outputfile = open('text_num.txt', 'a+') outputfile.write('{0} {1} '.format(x, line)) new_html.write('
{}{}
'.format(x, x, line)) x = x + 1 new_html.close()