在Python中将多个字段解析为单个颜色向量

在Python中将多个字段解析为单个颜色向量,python,parsing,3d,Python,Parsing,3d,Python中是否有一种好的模式可用于将输入文件的多行解析为单个值?例如,我有一个输入文件,看起来像: 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 我们的想法是将背景色转换成一个单一的颜

Python中是否有一种好的模式可用于将输入文件的多行解析为单个值?例如,我有一个输入文件,看起来像:

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

我们的想法是将背景色转换成一个单一的颜色向量对象以及DensityCorrection,但它们的大小不同,我希望避免每个参数都有特殊的逻辑。有什么想法吗?

你可以用ini文件解析器解析这样的文件


但数据结构取决于您。这取决于您的需要。

类似的方法应该可以工作(但在第一位使用configparser会更好):


您的数据有两种自然表示,一种基于配置文件的结构,另一种基于程序中的使用情况。从一种形式到另一种形式的转换的精神应该是明确的

BackgroundColor = (float(config['BackgroundColor_R']),
                   float(config['BackgroundColor_G']),
                   float(config['BackgroundColor_B']),
                   float(config['BackgroundColor_A']))
BackgroundColor = (float(config['BackgroundColor_R']),
                   float(config['BackgroundColor_G']),
                   float(config['BackgroundColor_B']),
                   float(config['BackgroundColor_A']))