我正在创建一个嵌套字典列表,以获得用于我的程序的图像的文件地址。但是,在BU0字典中,它似乎会导致以下错误:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 20-21: truncated \UXXXXXXXX escape下面是嵌套列表:
Bases = [
{
"BC0": ["Owl_project_pictures\Common\Great Grey Owl\_greatgrey_base.PNG", "Owl_project_pictures\Common\Great Grey Owl\_greatgrey_bonus1.PNG",
"Owl_project_pictures\Common\Great Grey Owl\_greatgrey_bonus2.PNG", "Owl_project_pictures\Common\Great Grey Owl\_greatgrey_accent.PNG",
"Owl_project_pictures\Common\Great Grey Owl\_greatgrey_shadows.PNG", "Owl_project_pictures\Common\Great Grey Owl\_greatgrey_eyesbeakfeet.PNG",
"Owl_project_pictures\Common\Great Grey Owl\_greatgrey_lines.PNG"],
"BC1": ["Owl_project_pictures\Common\Barn Owl\_barn_base.PNG", "Owl_project_pictures\Common\Barn Owl\_barn_bonus1.PNG",
"Owl_project_pictures\Common\Barn Owl\_barn_bonus2.PNG", "Owl_project_pictures\Common\Barn Owl\_barn_bonus2.PNG",
"Owl_project_pictures\Common\Barn Owl\_barn_accent.PNG", "Owl_project_pictures\Common\Barn Owl\_barn_shadows.PNG",
"Owl_project_pictures\Common\Barn Owl\_barn_eyesbeakfeet.PNG", "Owl_project_pictures\Common\Barn Owl\_barn_lines.PNG"],
"BC2": ["Owl_project_pictures\Common\Burrowing Owl\_burrowing_base.PNG","Owl_project_pictures\Common\Burrowing Owl\_burrowing_bonus1.PNG",
"Owl_project_pictures\Common\Burrowing Owl\_burrowing_bonus2.PNG", "Owl_project_pictures\Common\Burrowing Owl\_burrowing_accent.PNG",
"Owl_project_pictures\Common\Burrowing Owl\_burrowing_shadows.PNG", "Owl_project_pictures\Common\Burrowing Owl\_burrowing_eyesbeakfeet.PNG",
"Owl_project_pictures\Common\Burrowing Owl\_burrowing_lines.PNG"]
},
{
# The section that causes the error
"BU0": ["Owl_project_pictures\Uncommon\Crested Owl\_crested_base.PNG", "Owl_project_pictures\Uncommon\Crested Owl\_crested_bonus1.PNG"]
}
]发布于 2022-09-02 21:45:47
试着避开反斜杠:
...
{
"BU0": [
"Owl_project_pictures\\Uncommon\\Crested Owl\\_crested_base.PNG",
"Owl_project_pictures\\Uncommon\\Crested Owl\\_crested_bonus1.PNG",
]
}
...或者将它们作为原始字符串r"..."
...
"BU0": [
r"Owl_project_pictures\Uncommon\Crested Owl\_crested_base.PNG",
r"Owl_project_pictures\Uncommon\Crested Owl\_crested_bonus1.PNG",
]
}
...https://stackoverflow.com/questions/73588096
复制相似问题