Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Pillow having error with dictionaries nested in list

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading