Save and load initialized class
Steve D'Aprano
steve+python at pearwood.info
Sun Dec 10 06:00:27 EST 2017
On Sun, 10 Dec 2017 04:52 am, MRAB wrote:
> Try updating __dict__:
>
> Opts.__dict__.update(json.load(open("mybuffer")))
__dict__ is implementation, vars() is the public interface:
vars(Opts).update(json.load(open("mybuffer")))
Looks nicer too :-)
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list