나는 다양한 데이터 구조 (예 1)로 다른 YAML 파일을 가지고있다. 내 프로젝트에서, 나는 그 파일들로부터 약간의 정보를 가져야 만한다. 필요한 리소스를 사용하기 위해 다른 YAML 파일을 작성했습니다 (예제 2).파이썬 : 다른 yaml 파일의 yaml 데이터
예제 파일
res1.yaml
:--- form_title: mytitle icons: 1: icon: dog_icon link: '/my/file/path1/file1' 2: icon: wolf_icon link: '/my/file/path2/file2' 3: icon: cat_icon link: '/my/file/path3/file3' 4: icon: rabbit_icon link: '/my/file/path4/file4' ---
예
myapp_res.yaml
파일 :--- resources: 1: res: res1.yaml res_type: yaml 2: res: res2.jpg res_type: image data: my_form_title: res: 1 type: text var: form_title my_needed_icon: res: 1 type: icon var: icons: 1: link #etc... ---
내가 "my_form_title"와 같은 정보를 얻기 위해이 스크립트를 사용 :
import ruamel.yaml as yaml
myapp_res = yaml.load(myapp_res.yaml)
test_var = "my_form_title"
my_data = myapp_res["data"][test_var]
my_resource = my_data["res"]
my_res_file = myapp_res["resources"][my_resource]["res"]
yamel_res = yaml.load(my_res_file)
my_var = my_data["var"]
print(yamel_res[my_var])
하지만 "my_needed_icon"과 같은 하위 경로에서 어떻게 데이터를 가져올 수 있습니까?
TypeError: unhashable type: 'dict'
가 난 단지 분명히 내 파이썬 스크립트를 myapp_res.yaml의 구조를 변경할 수 있습니다 : 이전 스크립트 가 나는 오류가 발생합니다.
이 줄
(
my_resources
에서 떨어s
주의). 수정 해줘서 고마워. – Luca@luca가 문제를 해결하는 경우 대답을 표시하고 다른 사람들이 문제를 해결했음을 알립니다. – Anthon