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
Post a Comment