I have a scenario where I want to read file using python.
Data in file: ABC.txt
"A","B","C"
"E","F","A"
"S","H","DD","ADF"
"G","L","LI","LO","YAU"
"H","KK","AD"
"J","GH","KL"
"L","OP","AM"
"O","LA","WE"
My Code:
with open('ABC.txt',"r") as f:
lines = f.readlines()
parameter = {"empid": "3", "empcd": "56", "ide": [lines]}
What I am actually looking is read file line by line and
should be passed as an argument to "ide": [line].
Assume it goes through first iteration, entire string -> "A","B","C" will be passed to "ide": ["A", "B", "C"].
parameter = {"empid": "3", "empcd": "56", "ide": ["A", "B", "C"]}
second iteration:
parameter = {"empid": "3", "empcd": "56", "ide": ["E", "F", "A"]}
third iteration:
parameter = {"empid": "3", "empcd": "56", "ide": ["S", "H", "DD", "ADF"]}
Loop will continue until all records are read from file.
In Unix I know how to read file but not good with python how to achieve this using python ?
My Unix code:
while read -r line
do
var=`echo $line`
parameter = '{"empid": "3", "empcd": "56", "ide": [ $(( var )) ] }'
done < ABC.txt