reading from list with paths
Larry Bates
larry.bates at websafe.com`
Wed Jun 25 11:55:09 EDT 2008
antar2 wrote:
> Hello,
>
> 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:
>
> /data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f01.TextGrid
> /data/chorec/chorec-nieuw/s01/S01C001M1/
> S01C001M1_1LGPseudo_f01.TextGrid
> /data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_AVI1_f01.TextGrid
>
> 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
>
> Antar2
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:
fp.close()
flist.close()
-Larry
More information about the Python-list
mailing list