I am trying to read multiple files from a folder (for example, spect1.txt, spect2.txt, ...) and store each file in different python objects objects (i.e. spect1, spect2, ...). Up to now, I have this code, which reads the file and stores it in a different file
import sys,os path = “/home/jayapal/Desktop/route/” fn = ‘/home/jayapal/Desktop/mapping/dem.txt’ target =open(fn, ‘w’) for filename in os.listdir(path): source = open(path + filename, “r”) target.write(source.read()) source.close() target.close()
How can I make the code to store the files in python objects?