Python Forum
Four text files input combinations into an output file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Four text files input combinations into an output file
#1
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'))
Reply
#2
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.
Reply
#3
especially provide some small (2-3 lines) samples for the files 'wood.txt', 'color.txt', 'year.txt', 'quality.txt'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Search for multiple unknown 3 (2) Byte combinations in a file. lastyle 7 1,257 Aug-14-2023, 02:28 AM
Last Post: deanhystad
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,054 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  output provide the filename along with the input file processed. arjunaram 1 903 Apr-13-2023, 08:15 PM
Last Post: menator01
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,046 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Finding combinations of list of items (30 or so) LynnS 1 836 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  azure TTS from text files to mp3s mutantGOD 2 1,638 Jan-17-2023, 03:20 AM
Last Post: mutantGOD
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,064 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  merge two csv files into output.csv using Subprocess mg24 9 1,689 Dec-11-2022, 09:58 PM
Last Post: Larz60+
Question Take user input and split files using 7z in python askfriends 2 1,029 Dec-11-2022, 07:39 PM
Last Post: snippsat
  Writing into 2 text files from the same function paul18fr 4 1,629 Jul-28-2022, 04:34 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020