linecache and glob

Jeremy Dillworth jdillworth at gmail.com
Thu Jan 3 22:39:06 EST 2008


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 could explain more about what you are trying to do and we
could help more?

Hope this helps,

Jeremy



On Jan 3, 10:02 pm, jo3c <JO3chi... at gmail.com> wrote:
> hi everyone happy new year!
> im a newbie to python
> i have a question
> by using linecache and glob
> how do i read a specific line from a file in a batch and then insert
> it into database?
>
> because it doesn't work! i can't use glob wildcard with linecache
>
> >>> import linecache
> >>> linecache.getline(glob.glob('/etc/*', 4)
>
> doens't work
>
> is there any better methods??? thank you very much in advance
>
> jo3c




More information about the Python-list mailing list