I'm working on loading a list of emoji characters in a simple python 3.6 script. The YAML structure is essentially as follows:
-
-
-
My python script looks like this:
import yaml
f = open('emojis.yml')
EMOJIS = yaml.load(f)
f.close()
I'm getting the following exception:
yaml.reader.ReaderError: unacceptable character #x001d: special characters are not allowed in "emojis.yml", position 2
I have seen the allow_unicode=True
option but that seems to only be available for yaml.dump. It appears that people have had some trouble with similar issues in Python2, but since all strings should be unicode, I'm having trouble figuring out why this isn't working.
I've also tried wrapping my emojis in quotes and using a customer constructor for 'tag:yaml.org,2002:str'. My custom constructor is never even hit presumably because the yaml lib is failing to recognize my emoji as having the string type. I also observe the same behavior when I define my emoji directly as a string in source.
Is there a way to load a yaml file containing emojis with PyYAML?