Issue
It has been asked: How to initialize a SimpleNamespace from a dict?
My question is for the opposite direction. How to initialize a dict from a SimpleNamespace?
Solution
from types import SimpleNamespace
sn = SimpleNamespace(a=1, b=2, c=3)
vars(sn)
# returns {'a': 1, 'b': 2, 'c': 3}
sn.__dict__
# also returns {'a': 1, 'b': 2, 'c': 3}
Answered By - Николай Гордеев
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.