I have the following code:
inputActionFile = '../action.txt'
inputDaerahFile = '../daerah.txt'
inputStuffFile = '../stuff.txt'
inputTermsFile = '../terms.txt'
outputFile = 'hasil.out'
inputAction = open(inputActionFile, 'r')
inputDaerah = open(inputDaerahFile, 'r')
inputStuff = open(inputStuffFile, 'r')
inputTerms = open(inputTermsFile, 'r')
output = open(outputFile, 'w')
for actionLine in inputAction:
for daerahLine in inputDaerah:
for stuffLine in inputStuff:
for termsLine in inputTerms:
keyword = actionLine.strip() + ' ' + daerahLine.strip() + ' ' + stuffLine.strip() + ' ' + termsLine
output.write(keyword)
inputAction.close()
inputDaerah.close()
inputStuff.close()
inputTerms.close()
output.close()
I expected the results to be looping through all these files and nesting them one by one to the output file. However, it just iterates the fourth loop. I was doing a similar thing in BaSH and want to see how to do it in Python. The BaSH code is as follows:
#!/bin/sh
input1=$1
input2=$2
input3=$3
input4=$4
output=$5
echo "###START###" > $output
#old_IFS=$IFS
IFS='
' # new field separator, EOL
for line1 in `cat $input1`;
do
for line2 in `cat $input2`;
do
for line3 in `cat $input3`;
do
for line4 in `cat $input4`;
do
echo $line1 $line2 $line3 $line4 >> $output;
done
done
done
done
unset IFS;
#IFS=$old_IFS