Hello!
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?
Cheers!

Dani

why would anyone wanna store an entire file content into a py object??

what about the size is about 4mb?? or 4gig?? Its just not a good idea.

Can you explian further why you need that and maybe we can advice/help you with something more useful...

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.