Is there a good pattern in Python to use for parsing multiple lines of an input file into a single value? For example, I’ve got an input file that looks something like:
BackgroundColor_R=0.0
BackgroundColor_G=0.0
BackgroundColor_B=0.0
BackgroundColor_A=0.0
DensityCorrection_Color_R=1.0
DensityCorrection_Color_G=1.0
DensityCorrection_Color_B=1.0
The idea is to get BackgroundColor into a single color vector object as well as DensityCorrection but they are of different sizes and I’ve like to avoid special logic for each parameter. Any ideas?
Your data has two natural representations, one based on the structure of the config file and one based on the usage within the program. In the spirit of PEP 20 (the Zen of Python) the conversion from one form to another should be explicit.