Python Forum
get variable of yaml file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get variable of yaml file
#1
Hello, I have some problem with my program. I have try to solve my problem by myself but I do something wrong. Here my yaml file.

role.one.name: werewolf
role.one.desc: you are a werewolf.

role.two.name: villager
role.two.desc: you are a villager.
And this is my python code.
import yaml
with open(r'/myyamlfile') as file:
            role=yaml.load(file, Loader=yaml.FullLoader)

#selecting the role randomly

yourrole=role.one.get("name")

avatarname.set("role", yourrole)
But I get this error
Error:
yourrole=role.one.get("name") AttributeError: 'dict' object has no attribute 'one'
I try many thing, like switch the number into letter ( like in this exemple). I don't know what I doing wrong. thank you for your reply.
Reply
#2
role appears to be a dict, given the error message. Perhaps you could at least try printing the keys in that dict? That would be a useful place to start. I imagine the docs for the module also tell you how to use it..
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020