I have got a namespace looking like this :
Namespace(aTQ=None, bE=None, bEQ=None, b=None, bQ=None, c=None,
c=None, cJ=None, d=None, g=None, jR=[‘xx’, ‘015’], lC=None, l=None)
How can I iterate through it so I can find and replace the ‘xx’ value for the “jR” key in place ?
I’m not sure what you know in advance, (the name
jR, or only that one name has anot Nonevalue) but you can try usingvars()which, like__dict__should be a dict that has the names in your namespace as its keys. So if you have the string'jR'somewhere,likewise, you can get the same dict using
namespace.__dict__instead ofvars()will leave you with the first value in
['xx','015']as the only value forjR.To be clear, since
vars()and__dict__both return dicts, you can iterate through them as: