Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Four text files input combinations into an output file
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 ?

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'))
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.
especially provide some small (2-3 lines) samples for the files 'wood.txt', 'color.txt', 'year.txt', 'quality.txt'

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  User Input and CSV File Davy_Jones_XIV 2 141 Mar-24-2020, 08:43 AM
Last Post: Davy_Jones_XIV
  Import Text, output curve geometry Alyner 0 188 Feb-03-2020, 03:05 AM
Last Post: Alyner
  csv file output rturus 7 213 Jan-30-2020, 02:09 PM
Last Post: buran
  Rename file from value in text file Nuge93 1 167 Jan-20-2020, 03:50 PM
Last Post: gruntfutuk
  File name as part of output file name Jeeping_Coder 1 168 Jan-10-2020, 03:43 PM
Last Post: Clunk_Head
  error merge text files ledgreve 3 213 Nov-18-2019, 12:41 PM
Last Post: DeaD_EyE
  Details of attachment files in a msg file such as file names save into a python list klllmmm 2 589 Nov-12-2019, 05:59 AM
Last Post: klllmmm
  namedtuples and text files menator01 4 202 Nov-02-2019, 12:28 PM
Last Post: menator01
  How to extract a matrix from .xml.gz file to a excel file or any other output? enyrb 0 204 Oct-21-2019, 01:01 PM
Last Post: enyrb
  Still playing with text files (Jose Portilla on Udemy) Drone4four 2 365 Oct-17-2019, 07:20 PM
Last Post: Drone4four

Forum Jump:

Users browsing this thread: 1 Guest(s)