I am creating a list of nested dictionaries to have the file addresses for images I will be using for my program. However, in the BU0 dictionary it seems to cause an error that reads:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 20-21: truncated \UXXXXXXXX escape
Here is the nested list:
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"]
}
]
CodePudding user response:
Try to escape the backslashes:
...
{
"BU0": [
"Owl_project_pictures\\Uncommon\\Crested Owl\\_crested_base.PNG",
"Owl_project_pictures\\Uncommon\\Crested Owl\\_crested_bonus1.PNG",
]
}
...
Or put them as raw strings r"..."
:
...
"BU0": [
r"Owl_project_pictures\Uncommon\Crested Owl\_crested_base.PNG",
r"Owl_project_pictures\Uncommon\Crested Owl\_crested_bonus1.PNG",
]
}
...