Python newbie here.
I installed PyYAML and tried using this bit of code I found modified on the net to parse a YAML file I was given.
import yaml
if __name__ == '__main__':
try:
foo = open("foo.txt","a+")
except:
print("Error in opening file.")
stream = open("s.yaml", 'r')
dictionary = yaml.load(stream)
#dictionary = yaml.SafeLoader(stream)
for key, value in dictionary.items():
foo.write(key + " : " + str(value)+"\n")
Then I saw in the output that yaml.load was deprecated because of security issues. So I tried running it using SafeLoader instead. But that gave me the error
Traceback (most recent call last):
File ".\parseYAML.py", line 11, in <module>
for key, value in dictionary.items():
AttributeError: 'SafeLoader' object has no attribute 'items'
I can't post the actual data file here for business reasons, but does anyone have any hints on how I can get SafeLoader to work?