reading from list with paths
google at mrabarnett.plus.com
Thu Jun 26 02:45:09 CEST 2008
On Jun 25, 10:00 pm, norseman <norse... at hughes.net> wrote:
> antar2 wrote:
> > 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
> > Thanks a lot
> > Antar2
> > --
> I think what you want is more like:
> contents of a file named printthem.py
> import os
> p = open('list.txt')
> for vpath in p:
> for f in os.listdir(vpath):
> print '\n\tContents of:',vpath+'/'+f
> f = open(vpath+'/'+f)
> print f.read()
> print '\n\t\t\t\tEND OF FILE\x0C'
> print "All Done. Is there any paper left?"
> usage: python printthem.py >/dev/lp0 Unix
> python printthem.py > prn: Microsoft
> On Microsoft use '\\' in place of '/' following each vpath above
> The \x0C is Ctrl-L aka: ff or FormFeed
FYI, Python also understands '\f' ('\x0c').
Interestingly, print repr('\a\b\f\n\r\t\v') gives '\x07\x08\x0c\n\r\t
\x0b'. Is that because '\n', '\r' and '\t' occur so often that it was
decided that they should be treated specially?
More information about the Python-list