reading from list with paths
larry.bates at websafe.com`
Wed Jun 25 17:55:09 CEST 2008
> Suppose this is a stupid question, but as a python beginner I
> encounter a lot of obstacles... so I would be very grateful with some
> help for following question:
> I would like to read files, of which the complete filepaths are
> mentioned in another textfile. In this textfile (list.txt) are for
> example the following paths:
> I know how to open and read one file in my current directory,
> but after trying to find this out my self, I give up...
> So could someone help me and write some code so that I know how to
> open and read the content of the mentioned files.
> Thanks a lot
You didn't say what you wanted to do with the data in each of the files, but
perhaps this will get you going.
flist = open('list.txt', 'r')
for fpath in flist:
fp = open(fpath, 'r')
# Do something with data in this file
for line in fp:
More information about the Python-list