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!!

Recommended Answers

All 3 Replies

I think you need to give us a bit more detail.

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.