strictyaml icon indicating copy to clipboard operation
strictyaml copied to clipboard

Acessing Values of Mapping via .data .value or .scalar

Open orangelynx opened this issue 5 years ago • 3 comments

I just started using strictyaml and was surprised that when lets say parsing

import strictyaml
from datetime import timedelta

config = strictyaml.load('stop_time: 2021-01-22T23:50:00', strictyaml.Map({'stop_time', strictyaml.Datetime()}))

newtime = config['stop_time'] + timedelta(seconds=300)

you get an error

TypeError: unsupported operand type(s) for +: 'YAML' and 'datetime.timedelta'

Now, the documentation isn't very concise how to access the actual value. .data is mentioned, but what about .value and .scalar. I looked at the code and can see the differences, but I'd like to hear an official "recommended procedure" for doing this (and I assume it's just going to be "use .data").

orangelynx avatar Feb 20 '20 08:02 orangelynx

yep, use .data

.value should be unused, really.

the YAML object itself is meant for editing and saving YAML (with comments preserved).

thanks for pointing this out though, looking at it from your perspective it's not super clear.

On Thu, 20 Feb 2020, 08:58 orangelynx, [email protected] wrote:

I just started using strictyaml and was surprised that when lets say parsing

import strictyamlfrom datetime import timedelta

config = strictyaml.load('stop_time: 2021-01-22T23:50:00', strictyaml.Map({'stop_time', strictyaml.Datetime()}))

newtime = config['stop_time'] + timedelta(seconds=300)

you get an error

TypeError: unsupported operand type(s) for +: 'YAML' and 'datetime.timedelta'

Now, the documentation isn't very concise how to access the actual value. .data is mentioned, but what about .value and .scalar. I looked at the code and can see the differences, but I'd like to hear an official "recommended procedure" for doing this (and I assume it's just going to be "use .data").

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/crdoconnor/strictyaml/issues/88?email_source=notifications&email_token=ABOJKNMJI55LWZBK2KFA4JDRDZA27A5CNFSM4KYKEWJ2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IO5HOEQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOJKNOTB6ZPMO6FNI3FUTLRDZA27ANCNFSM4KYKEWJQ .

crdoconnor avatar Feb 20 '20 10:02 crdoconnor