[Tutor] Using Regex from Configuration File

Kent Johnson kent37 at tds.net
Fri Jun 20 16:36:05 CEST 2008


On Fri, Jun 20, 2008 at 10:04 AM, Tyler Rutschman <trutch at gmail.com> wrote:

> 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]+"\"\"\""

Leave this out, just use the string from load_config() directly.

the r""" """ around the string are Python syntax, they should not be
part of the actual string.

Kent

> ...
> 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
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


More information about the Tutor mailing list