May-05-2019, 02:43 AM
(May-04-2019, 08:21 PM)snippsat Wrote: You useclose()
that's not needed when usewith open
and there is nowrite()
.
Here how it look if write result to file.
def line_concat(lst): temp = zip(lst[::2], lst[::-2]) return [':'.join(i) for i in temp] def file_read(file_in): with open(file_in) as f: lst = [line.strip() for line in f if not line.isspace()] return lst if __name__ == '__main__': file_in = 'xy.txt' lst = file_read(file_in) #print(lst) # Test file read with open('xy_new.txt', 'w') as f_out: for line in line_concat(lst): f_out.write(f'{line}\n')
Thank you so much!
After some error on my side of files showing up blank, I got it with your help!
Cheers!