On Apr 25, 8:37 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > micron_make <[EMAIL PROTECTED]> writes: > > I am trying to parse a file whose contents are : > > > parameter=current > > max=5A > > min=2A [snip] > 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? Chris -- http://mail.python.org/mailman/listinfo/python-list