How to get value from set with key containing a single quote loaded with YAML?

Couldn’t find any material on this question.

I have a yaml file containing:

items : - "jeweller's orb" 

I then load it:

with open('./configs/items.yaml') as f:     data = yaml.safe_load(f) self.item_set = set([x.upper() for x in data['items']]) 

Now how do I access the set with a key containing a single quote?? I’ve tried escaping it, double single quoting it, nothing works…

print('JEWELLER\’S ORB' in self.item_set) print("JEWELLER\’S ORB" in self.item_set) print('JEWELLER’S ORB' in self.item_set) print("JEWELLER’S ORB" in self.item_set) print(r'JEWELLER’S ORB' in self.item_set) print(r"JEWELLER’S ORB" in self.item_set) 

They all return false. Something with yaml behind the scenes I am not aware of??

I’ve tried also copying the output of the variables in the self.item_set and directly using it in the print. Still nothing.

EDIT: The answer was

with open('./configs/items.yaml', 'rt', encoding='utf8') as f: 

As well as using the opening single quote version in the yaml instead of straight single quote. Wow, what a pain.

Add Comment
1 Answer(s)
with open('./configs/items.yaml', 'rt', encoding='utf8') as f: 

As well as using the opening single quote version in the yaml instead of straight single quote. Wow, what a pain.

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.