Opening text files from a list within another text file using python -


i'm doing silly , basic, can't bit of code work. have text file contains list of more text files (log files) full path them. want open first file, grab list , open each in turn (ultimately search within each errors) , close them. problem having can't data newly opened secondary files display.

text file 1 (logs.txt) :

//server-1/program/data/instances/devapp/log/audit.log

//server-2/program/data/instances/devapp/log/bizman.db.log

the code trying run:

import os  logdir = '/cygdrive/c/bob/logs.txt'  load_log_file = open (logdir, 'r') read_log_file = load_log_file.readlines ()  def txt_search (read_log_file) :     entry in read_log_file :         view_entry = open (entry, 'a+wb')         print view_entry  print txt_search (read_log_file) 

the output looks following:

$ python log_4.py <open file '//server-1/program/data/instances/devapp/log/audit.log ', mode 'a+wb' @ 0xfff3c180> <open file '//server-2/program/data/instances/devapp/log/bizman.db.log ', mode 'a+wb' @ 0xfff3c1d8> none 

any appreciated i'm getting point of pulling hair out!

many thanks,

bob

you can this:

logdir = r"/cygdrive/c/bob/logs.txt"  open(logdir) fin:     line in fin:         open(line.strip()) log:             print log.readlines() 

if want print files seen, without surrounding brackets , other list markup, can use following line:

print "".join(log.readlines()) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -