The title is fairly self-explanatory.
When I save a tuple to a YAML file, I get something that looks like this:
ambient: !!python/tuple [0.3, 0.3 ,0.3]
When I try to load it with yaml.safe_load(file_object), I keep getting an error that reads:
yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:python/tuple'
What needs to be done?
In pyyaml, the SafeLoader does not include a loader for the python native types, only the types defined in the yaml spec. You can see the types for the
SafeLoaderand theLoaderhere in the interaction sample below.You can define a new Loader class that adds in the python tuple, but not other types, so it should still be pretty safe:
resulting in:
See below for the constructors associated with the SafeLoader and the Loader classes.