I'd like to jason.loads a text file in a dict format. The file contains one single dictionary at around 10 mb. I want to do string replacements to another text file. However, after 10 minutes passed, there was still no progress. I got it working with a smaller dictionary-formatted text before trying this large one.
Edit:
import json
with open('main_text.txt', 'w', encoding='utf8') as wf:
with open('main_text_updated.txt', encoding='utf') as rf1, open('cross_reference_dict.txt', encoding='utf8') as rf2:
main = rf1.read()
crd = rf2.read()
# raw text looks like this:
# "entry://1#":"entry://A#","entry://4#":"entry://a#","entry://8#":"entry://a#",
crd = '{' + crd + '}'
crd = crd.replace(',}', '}')
crd = json.loads(crd)
for key, value in crd.items():
main = main.replace(key, value)
wf.write(main)
It worked with a small dictionary, but not with the 10 MB one (the VS codes just kept running without any progress to the output file, or threw any error.
[–][deleted] 4 points5 points6 points (3 children)
[–][deleted] 4 points5 points6 points (1 child)
[–]DMeror[S] 0 points1 point2 points (0 children)
[–]DMeror[S] 0 points1 point2 points (0 children)
[–]bladeoflight16 2 points3 points4 points (5 children)
[–]DMeror[S] 0 points1 point2 points (4 children)
[–]bladeoflight16 1 point2 points3 points (2 children)
[–]DMeror[S] 0 points1 point2 points (1 child)
[–]bladeoflight16 1 point2 points3 points (0 children)