I am reading from a text file and writing to a CSV using DictWriter
. Now I want to implement the same code for several text files and write to different CSV files. I want to use a properties.py
file for this purpose like:
input1 = "file1.txt"
output1 = "mycsv1.csv"
input2 = "file2.txt"
output2 = "mycsv2.csv"
and so on.
I tried using import and other methods specified in links such as "what would be a quick way to read a property file in python?" and "Using ConfigParser to read a file without section name", but could not solve this issue.
Part of my code:
with open("mycsv1.csv") as f:
writer = csv.DictWriter(f, ['name', 'age', 'addr'], delimiter=',')
writer.writeheader()
with open("file1.txt") as fil:
# rest of the operations
How can I change my code to make use of my properties.py
file, i.e. each of the input files in the properties file are read one by one, and the output gets stored in the corresponding output csv?