reading from list with paths

Cédric Lucantis omer at no-log.org
Wed Jun 25 15:24:25 EDT 2008


Le Wednesday 25 June 2008 20:59:38 antar2, vous avez écrit :
> Hello,
>
> I would like to  read and print 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...
>
> I already got one answer for this question, but it did not work
>

What's the problem exactly ? If you already know how to read a file you have 
all what you need:

f_list = open('list.txt')
for filename in f_list :
	f = open(filename)
	print f.read()
	f.close()
f_list.close()

If you get an error, please post the full error message with the backtrace.

-- 
Cédric Lucantis



More information about the Python-list mailing list