On Jan 4, 5:25 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> jo3c wrote:
> > i have a 2000 files with header and data
> > i need to get the date information from the header
> > then insert it into my database
> > i am doing it in batch so i use glob.glob('/mydata/*/*/*.txt')
> > to get the date on
jo3c wrote:
> i have a 2000 files with header and data
> i need to get the date information from the header
> then insert it into my database
> i am doing it in batch so i use glob.glob('/mydata/*/*/*.txt')
> to get the date on line 4 in the txt file i use
> linecache.getline('/mydata/myfile.txt/,
import linecache
import glob
# reading from one file
print linecache.getline('notes/python.txt',4)
'http://www.python.org/doc/current/lib/\n'
# reading from many files
for filename in glob.glob('/etc/*'):
print linecache.getline(filename,4)
jo3c wrote:
> hi everyone happy new year!
> im a
i have a 2000 files with header and data
i need to get the date information from the header
then insert it into my database
i am doing it in batch so i use glob.glob('/mydata/*/*/*.txt')
to get the date on line 4 in the txt file i use
linecache.getline('/mydata/myfile.txt/, 4)
but if i use
linecac
Hello,
Welcome to Python!
glob returns a list of filenames, but getline is made to work on just
one filename.
So you'll need to iterate over the list returned by glob.
>>> import linecache, glob
>>> for filename in glob.glob('/etc/*'):
>>> print linecache.getline(filename, 4)
Maybe you coul