Whenever there is a matching keyword, my code prints the next line. I'm trying to export the entire print output to an excel file automatically. The code works perfectly for printing the output in the IDE terminal, but I can't seem to export it to excel. The for loop is giving me trouble. Which ever command I try, ends up giving an error. Any pointers in the right direction are much appreciated.
Sample text to try the code on:
Hi, please enter name
Ricky
can you please enter last name
Martin
Please enter the full name
Ricky Martin
Output:
Ricky
Martin
Ricky Martin
Question
How to get these outputs exported to a column in Excel?
import xlsxwriter
excelFile = xlsxwriter.Workbook ("goal.xlsx")
workSheet = excelFile.add_worksheet ()
with open("filepath.txt", 'r') as f:
for line in f:
if "enter" in line:
result = print(next (f, ''))
workSheet.write('A1', result)
excelFile.close()