I extracted information from two XML files into 2 dictionaries because I wanted to compare these files and change information in one of them.
These are my dictionaries:
source dictionary:
d_source={'123': 'description_1', '456': 'description_2'}
target dictionary:
d_target={'123': '\n', '456': 'description_2'}
This is my replacement code:
for i in d_source:
for j in d_target:
if d_target[j]=='\n':
d_target[j]=d_source[i]
print (d_target)
d_target is updated to
d_target = {'123': 'description_1', '456': 'description_2'}
However, my original files from which I extracted the dictionaries remain unchanged. What am I missing here?
One of the solutions for you would be:
Let’s say you want to print it as a json, it makes sense if you are already using dicts.
This will print your dict to file myfile as a json.
And if you want it as a xml you can use elementtree module.
Then you could use something like this:
This is just an example to see how it is done and this would create something like:
And to print this xml to file again: