[Tutor] Using Regex from Configuration File
Tyler Rutschman
trutch at gmail.com
Fri Jun 20 16:04:14 CEST 2008
Hello everyone,
I'm new to python and have set up a program to parse through reports. The
script has started very basic and I've been folding in additional features
as it moves along. What it does is takes a specified log file (exported from
splunk) and parses through it with a regex specific to the type of log.
It is invoked by: ./extract -f filename -c config
I've successfully set up ConfigParser to go through the config and apply the
proper configuration to the script, but I'm having trouble getting the regex
to work. It worked successfully when I declared it within the script.
---------------- code ----------------
def load_config():
configdict = ConfigParser()
configdict.read('report.conf')
conf=main()[0]
opt_name = configdict.get(conf,'name')
opt_regex = configdict.get(conf,'regex')
return opt_name,opt_regex
...
rawstr="r"+"\"\"\""+load_config()[1]+"\"\"\""
...
rxinput = re.compile(rawstr)
---------------- code ----------------
full code here http://codepad.org/pva1dE1i
configuration here http://codepad.org/VnXfQhBi
Any help would be appreciated.
Thanks,
Tyler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080620/b5fd5723/attachment.htm>
More information about the Tutor
mailing list