Skip to content

Customizing arepl output

Almenon edited this page Feb 15, 2019 · 1 revision

AREPL works by using jsonpickle to pickle your variables into json. You can control how your object gets pickled by adding a __getstate__(self) method, like shown below:

class calculator:
    def __init__(self, num):
        self.num = 5
    def exponent(self):
        return self.num*self.num
    def __getstate__(self):
        return "custom debug info: exponent is " + str(self.exponent())

f = calculator(5)

# normally, f: {a: 5} is shown
# but instead, we see f: {py/state: "custom debug info: exponent is 25"}