Monday 28 September 2020

How to make a python objects self or attribute not get assigned to the referencer object when it is references?

I want when a object is referenced by another, the refernecer's self object or one of it's attributes to be different at the referencer object

This is what I want to do:

class MyClass:
    .
    .
    .
    .

a = MyClass()
b = a
print(b is a) #must print false
print(b == a) #must print true

#or
a = MyClass()
b = a
print(b.attr is a.attr) #must print false
print(b.attr == a.attr) #must print true

How can I achieve this, normally the when an assignment is made like a = b, b is a reference to a, any help would be appreciated, I want b to be a copy/deepcopy of a, same for the attribute

Thanks from now for the people who will answer the question

Note: I’m using CPython (the official implemention of Python) version Python 3.8

I'm open for using dark magic



from How to make a python objects self or attribute not get assigned to the referencer object when it is references?

No comments:

Post a Comment