reading from list with paths

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • antar2

    reading from list with paths

    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_f 01.TextGrid
    /data/chorec/chorec-nieuw/s01/S01C001M1/
    S01C001M1_1LGPs eudo_f01.TextGr id
    /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
  • Larry Bates

    #2
    Re: reading from list with paths

    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_f 01.TextGrid
    /data/chorec/chorec-nieuw/s01/S01C001M1/
    S01C001M1_1LGPs eudo_f01.TextGr id
    /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

    Comment

    Working...