Open Fuhrmann opened 4 years ago
@Fuhrmann
You could use the following model:
import related
@related.immutable
class Settings(object):
devices = related.MappingField(str, "name")
Explanation:
Your YAML file is syntactically equivalent to the following Dictionary:
{
'devices': {
'left-keyboard': '000123456789',
'right-keyboard': '000987654321',
}
}
So
{
'left-keyboard': '000123456789',
'right-keyboard': '000987654321',
}
is passed to the MappingField
. So 'left-keyboard'
will be used as the name and 000123456789
to whatever class is passed to the cls
parameter of MappingField
- in our example this is str
.
Hi! I'm trying to use your library with a custom yaml file I have:
How could I represent this yaml in a class? I've tried this:
But it gives me an error:
TypeError: 000123456789 is not an instance of <class '__main__.Device'>
I've tried using
SetField
,SequenceField
and others in this case but to no success.