def __init__(self, name, surname):
    self.name = name
self.surname = surname
user = User('spam', 'eggs')
serialized_user = yaml.dump(user)
deserialized_user = yaml.safe_load(serialized_user)
print('name: %s, sname: %s' % (deserialized_user.name, deserialized_user.
    surname))
How to deserialize an object with PyYAML using safe_load?