user6769219
user6769219

Reputation: 90

How to ignore/overwrite setters in Python?

I have a Requests response object, r. r gets passed into a callback function as an argument. I want to perform an action on r.text, and then return the full r object.

However, when I try to reassign r.text,

AttributeError: can't set attribute

is thrown

Upvotes: 0

Views: 118

Answers (1)

pktangyue
pktangyue

Reputation: 8524

The text attribute is a propery without setter. If you want to modify it, you should copy it to a new variable like this:

from copy import copy
my_text = copy(r.text)

Upvotes: 1

Related Questions