Hi experts I’m looking to make a loop of reading a text file then output (8) text files with the following code:
for i in range(1,9):
with open(inputgui, 'r') as input1:
junkinfo = [next(input1) for dummy in range(22)]
with open(output, 'w') as output1:
for line in input1:
columns = line.strip().split()
output1.write('{:8}{:8}\n'.format(columns[1], columns[i+1]))
Note that variable inputgui is a text variable from a user and output is a text variable from a user. Example, the user in the gui will select 'C:/Data.txt' and will want to name the output and iterate 8 times to produce 'C:/NewData1.txt', 'C:/NewData2.txt', etc. How do I format variable output to iterate or most efficient way?
Assuming that the user provides a file name with a .txt extension you can do this:
If the extension is unknown you will need to find where the . is and splice based on its location