I have a python script that will take a text file and insert each line of text into an appropriate column. What I would like to do is import lines of text from multiple files and have it write the string in an appropriate area. Here is the code snippet.
input_file = input("Path To The Class File: ")
output_file = input("Output File Path: ")
text_file = open(input_file, "r")
output_file = open(f"{output_file}/Output.txt", "a")
lines = text_file.readlines()
final_lines = []
for x in lines:
z = x.replace("\n", "")
final_lines.append(z)
b = ""
for in final_lines:
output_file.write(' {\n')
output_file.write(f' "dna_Tier": "yellow",\n')
output_file.write(f' "dna_Helm": "{i}",\n')
output_file.write(f' "dna_Shirt": "",\n')
output_file.write(f' "dna_Vest": "",\n')
output_file.write(f' "dna_Pants": "",\n')
output_file.write(f' "dna_Shoes": "", \n')
output_file.write(f' "dna_Backpack": "",\n')
output_file.write(f' "dna_Gloves": "",\n')
output_file.write(f' "dna_Belt": "",\n')
output_file.write(f' "dna_Facewear": "",\n')
output_file.write(f' "dna_Eyewear": "",\n')
output_file.write(f' "dna_Armband": "",\n')
output_file.write(f' "dna_NVG": ""\n')
output_file.write(' },\n')
output_file.close()
text_file.close()
It is for creating a json file format, and what I would like to do is import from multiple files. Each file would correspond with a type of clothing. I would like the script to write from corresponding file into a corresponding column.
TIA
input_file = input("Path To The Class File: ")
output_file = input("Output File Path: ")
text_file = open(input_file, "r")
output_file = open(f"{output_file}/Output.txt", "a")
lines = text_file.readlines()
final_lines = []
for x in lines:
z = x.replace("\n", "")
final_lines.append(z)
b = ""
for in final_lines:
output_file.write(' {\n')
output_file.write(f' "dna_Tier": "yellow",\n')
output_file.write(f' "dna_Helm": "{i}",\n')
output_file.write(f' "dna_Shirt": "",\n')
output_file.write(f' "dna_Vest": "",\n')
output_file.write(f' "dna_Pants": "",\n')
output_file.write(f' "dna_Shoes": "", \n')
output_file.write(f' "dna_Backpack": "",\n')
output_file.write(f' "dna_Gloves": "",\n')
output_file.write(f' "dna_Belt": "",\n')
output_file.write(f' "dna_Facewear": "",\n')
output_file.write(f' "dna_Eyewear": "",\n')
output_file.write(f' "dna_Armband": "",\n')
output_file.write(f' "dna_NVG": ""\n')
output_file.write(' },\n')
output_file.close()
text_file.close()
It is for creating a json file format, and what I would like to do is import from multiple files. Each file would correspond with a type of clothing. I would like the script to write from corresponding file into a corresponding column.
TIA