![]() In order to represent static Python objects like functions or classes, you need to use a complex !!python/name tag. For compatibility reasons, tags !!python/str and !!python/unicode are still supported and converted to str objects. In Python 3, str objects are converted to !!str scalars and bytes objects to !!binary scalars. a !!python/unicode scalar if its value is ASCII. a !!binary scalar otherwise.Ī unicode object is converted to 1. a !!python/str scalar if its value is a correct utf-8 sequence. !!python/unicode scalars are converted to unicode objects.Ĭonversely, a str object is converted to 1. !!python/str scalars are converted to str objects encoded with utf-8 encoding. !!binary-tagged scalars are converted to str objects with its value decoded using the base64 encoding. !!str-tagged scalars are converted to str objects if its value is ASCII. There are four tags that are converted to str and unicode values: !!str, !!binary, !!python/str, and !!python/unicode. The following table describes how nodes with different tags are converted to Python objects. PyYAML allows an application to add custom implicit tag resolvers. The scalar value is checked against a set of regular expressions and if one of them matches, the corresponding tag is assigned to the scalar. Plain scalars without explicitly defined tags are subject to implicit tag resolution. ![]() The yaml.dump function accepts a Python object and produces a YAML document. To do this, derive it from yaml.YAMLObject (as explained in section Constructors, representers, resolvers) and explicitly set its class property yaml_loader to yaml.SafeLoader. The function yaml.safe_load limits this ability to simple Python objects like integers or lists.Ī python object can be marked as safe and thus be recognized by yaml.safe_load. Note that the ability to construct an arbitrary Python object may be dangerous if you receive a YAML document from an untrusted source such as the Internet. _name_, self.name, self.hp, self.sp) > yaml.load( """. yaml.dump(data, encoding=('utf-8'|'utf-16-be'|'utf-16-le')) produces a bytes object in the specified encoding.yaml.dump(data) produces the document as a str object.For compatibility reasons, !!python/str and !python/unicode tags are still supported and the corresponding nodes are converted to str objects.bytes objects are converted to !!binary nodes. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |