0

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"]
    }
]
D.L
  • 4,339
  • 5
  • 22
  • 45
  • write the error as text and not a picture please... – D.L Sep 02 '22 at 21:46
  • the issue is with path '\U' initiates unicode escape, hence the compiler gives 'unicodeescape' error interpreting it as a unicode escape - https://stackoverflow.com/a/1347854/8321379 – skt7 Sep 02 '22 at 21:50
  • Does this answer your question? [Windows path in Python](https://stackoverflow.com/questions/2953834/windows-path-in-python) – skt7 Sep 02 '22 at 21:51
  • as per the above: replace backslash ( \ ) with forwardslash ( / ) . – D.L Sep 02 '22 at 21:52

1 Answers1

1

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",
        ]
    }

...
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91