Current task is to pull only numbers from a text file. I have this part working and it's printing vertically in the console.
I'm trying to print my output to an CSV or Excel file. Preferably to the same column. Can I just replace my print line with f.save()
?
import re
import xlwt
f = open('printouthg.csv','w')
file_name = r'C:\Users\hank\desktop\pycodes\numbers.txt'
with open(file_name, 'r') as file:
filedata = file.read()
lines = filedata
import re
output = []
repl_str = re.compile('\d+.?\d*')
#t = r'\d+.?\d*'
line = lines.split()
for word in line:
match = re.search(repl_str, word)
if match:
output.append(float(match.group()))
print(*output, sep='\n')