1

I use the PPTX library to automate the creation of a deck of slides on a weekly basis. It was working really well until the last update of the library. As you can see below, I keep getting the following when updating the "image part" of the slides:


AttributeError: 'SlidePart' object has no attribute 'related_parts'


Here is my function for the image replacement:


def replace_img_slide(prs, slide_nbr, shape_nbr, img_path):

slide = prs.slides[slide_nbr]
img = slide.shapes[shape_nbr]
try:
    imgPic = img._pic
except AttributeError:
    raise AttributeError(
        f"Error for slide: {slide_nbr}, shape: {shape_nbr}, path: {img_path}")
imgRID = imgPic.xpath('./p:blipFill/a:blip/@r:embed')[0]
imgPart = slide.part.related_parts[imgRID]

with open(img_path, 'rb') as f:
    rImgBlob = f.read()

# replace
imgPart._blob = rImgBlob

return prs

I found some related subject and I understood that the "related_parts" is now obsolete in the new version of the library but I did not find how to solve it. Do you think you can help me with that please ?

Many thanks in advance for your help !

1 Answer 1

3

Just use part.related_part(imgRID) where you used to use part.related_parts[imgRID].

The latest version exposes that method (internally) rather than expose a dict-like object just to do that one job.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Scanny, it works, thanks a lot for that ! Also, I saw some of your answers in others topics related to similar issues, it was really helpful, so thanks again !
Welcome to StackOverflow @Reda. Be sure to accept an answer that resolves your question. That's how you say Thank You! on SO :) Just click on the checkmark to the left of the answer. That helps others locate an answer that worked and also gives you reputation points.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.