擅长:python、mysql、java
<p>我的<a href="https://github.com/SzieberthAdam/jsonfile" rel="nofollow noreferrer">jsonfile</a>模块检测(嵌套的)JSON兼容Python对象的更改。只需子类<code>JSONFileRoot</code>就可以根据需要调整变更检测。在</p>
<pre><code>>>> import jsonfile
>>> class Notify(jsonfile.JSONFileRoot):
... def on_change(self):
... print(f'notify: {self.data}')
...
>>> test = Notify()
>>> test.data = 1
notify: 1
>>> test.data = [1,2,3]
notify: [1, 2, 3]
>>> test.data[0] = 12
notify: [12, 2, 3]
>>> test.data[1] = {"a":"b"}
notify: [12, {'a': 'b'}, 3]
>>> test.data[1]["a"] = 20
notify: [12, {'a': 20}, 3]
</code></pre>