multiple pattern regular expression

Chris Henry at
Sat Apr 26 07:55:32 CEST 2008

On Apr 25, 8:37 pm, Arnaud Delobelle <arno... at> wrote:
> micron_make <micro_pass... at> writes:
> > I am trying to parse a file whose contents are :
> > parameter=current
> > max=5A
> > min=2A
> If every line of the file is of the form name=value, then regexps are
> indeed not needed.  You could do something like that.
> params = {}
> for line in file:
>     name, value = line.strip().split('=', 2)
>     params[name] = value
> (untested)
> Then params should be the dictionary you want.
I'm also interested in this problem. While this solution works, I'm
looking for solution that will also check whether the parameter name/
value is of a certain pattern (these patterns may be different, e.g.
paramA, paramB, paramC may take integers value, while paramD may take
true/false). Is there a way to do this easily?

I'm new to Python and the solution I can think off involve a loop over
a switch (a dictionary with name->function mapping). Is there other,
more elegant solution?


More information about the Python-list mailing list