I am very new to both Python and programming. I am in need of some help with this small project that I am working on. I have several text files in a directory. I want to compile them into one master file. There is a common variable, x and y coordinate, in all files. So I will need to match them up and then co-responding values from each txt files. so the master file should look something like this:

X Y txt01.val01 txt02.val01 txt03.val01...........
0 0 5 2 3
0 1 3 3 12

I was thinking to store each files into a dictionary using (x,y) as key and [val01, val02....] as values. Then write them to a new file. Would that work? or is there a better/simpler way of doing this?

Thanks a lot!!

8 Years
Discussion Span
Last Post by linux

I would just read the first file then write that to then master file, then read the second file and write to the master file, then read the third file and write it to the master file, etc.


I hate to be the guy that tells you to use the os module, but, wouldn't:

import os
x = "Hello "
y = "World"
os.system("echo " + x + " > MasterFile.txt")
os.system("echo " + y + " > MasterFile.txt")

Etc. work? Or will that overwrite it?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.