2

Look at code in my python file:

class Point:
    def __init__(self):
        """ Create a new point at the origin """
        self.x = 0
        self.y = 0
p = Point()
p.x = 4
p.y = 4

I want to create another object q which contains all the values of p

Yes,we can do it like this: q = Point.objects.create(q.x = p.x,q.y = p.y)

But, I don't want to refer to all the variables inside the class Point

How can I do it ?

2

1 Answer 1

4
import copy

for a shallow copy use

p2 = copy.copy(p)

for a deep copy use

p2 = copy.deepcopy(p)
Sign up to request clarification or add additional context in comments.

Comments

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.