I am newbie in Python and try to read a YAML-File. Based on its content, I want to create Python objects. I am using ruamel-yaml library. In my case, maybe I have Python-Classes Message, Signal and Signalgroup etc. (See the example file).
My approach would be to read the YAML file, check each line for a given key word and create the related object and fill it with data. I think it is the “old school” approach and maybe there is a much more effective approach to process the file.
Maybe using the function register_class/ rep. creating tags “from_yaml” but as the keys are indexed it would not work.
Message1:
Message2:
Message3:
Is there any much more professional approach?
# Yaml Testfile
- ModuleName: myTestModule
- Version: 1.0
- ModuleNumbers: [96,97,98,99]
- Message1:
Name: AO3_
DLC: 8
Signal1:
Name: Temperature
Length: 16
Signal2:
Name: AnalogOut3
Length: 16
SignalGroup1: #Comment
Name: app_fcex
Type: Bitfield
Signal1:
Name: drive_ready
Length: 1
Signal2:
Name: error_active
Length: 1
Signal3:
Name: warning_active
Length: 1
Signal3:
Name: Temperatur 2
Length: 8
ValueTable:
Name: TempStates
Item0:
Name: INIT
Value: 1
Item1:
Name: RUN
Value: 2
Item2:
Name: DONE
Value: 3
Item3:
Name: ERROR
Value: 4
- Message2:
name: AO2_
object: RX2
DLC: 8
from_yamlnot work "because the keys are indexed" that doesn't make much sense.