Four text files input combinations into an output file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Four text files input combinations into an output file (/thread-20118.html) |
Four text files input combinations into an output file - mhyga - Jul-28-2019 Hello everyone, I need your help about the script below. Originally, I wanted to have all datas product from 4 text files inputs. Each text file contains from 20 to 55 lines. The script below works as intended but now, I would like them to be saved in a text file. I tried different ways, but I can't find a solution by myself. I still have trouble understanding how to structure the record in a file. I specify that I don't need the different combinations appears in the editor, only in the output text file. Can anyone provide me some help/advice ? Thanks import fileinput from itertools import product from contextlib import closing with closing(fileinput.input(['wood.txt', 'color.txt', 'year.txt', 'quality.txt'])) as f: for w, x, y, z in product(f, repeat=4): print '{}-{}-{}-{}'.format(w.rstrip('\n'),x.rstrip('\n'), y.rstrip('\n'), z.rstrip('\n')) RE: Four text files input combinations into an output file - woooee - Jul-28-2019 Quote:I tried different ways, but I can't find a solution by myself.Post the code for the ways that you have tried and we should be able to get one of them working. RE: Four text files input combinations into an output file - ThomasL - Jul-28-2019 especially provide some small (2-3 lines) samples for the files 'wood.txt', 'color.txt', 'year.txt', 'quality.txt' |