0

I am trying to deep copy a Powerpoint object in Python. When I try to copy the presentation object to a new variable it gives an error. When doing a shallow copy it does not give any errors, so it has something to do with the deep copy.

Expected output

Makes a copy of the presentation object without errors.

from pptx import Presentation
import copy

prs1 = Presentation()
prs1.slide_width = Cm(75)
prs1.slide_height = Cm(45)
slide_layout = prs1.slide_layouts[6]
slide = prs1.slides.add_slide(slide_layout)
shapes = slide.shapes

prs2 = copy.deepcopy(prs)


TypeError: __new__() missing 1 required positional argument: 'xFill'

I know it has been asked before, but I don't get it. What do I have to add as argument? __new__?

This also gives a error: prs2 = copy.deepcopy(prs, Presentation.__new__)

Also a shallow copy does not work, because when I change something in the copied object the orginal object changes aswell.

kevin
  • 21
  • 4
  • The `prs` in `copy.deepcopy(prs)` is not defined in the code you've shown. Where is it coming from? – scanny Nov 29 '21 at 18:10

2 Answers2

0

change prs to prs1 in the below line because only prs1 is used in the code so far

prs2 = copy.deepcopy(prs)
Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35
user3626733
  • 41
  • 1
  • 1
  • 6
0

Try to use python 3.10. There are no problem.
But somebody already faced problem with collections import:

import collections 
import collections.abc
from pptx import Presentation
xillmera
  • 22
  • 3