Untitled
unknown
python
4 years ago
1.4 kB
6
Indexable
I used the codes posted here = https://stackoverflow.com/questions/57015170/how-to-merge-and-split-again-thousands-of-text-files import os import glob #merging code // merge.py import os import glob with open("common.json", "w", encoding="utf8") as common: for json in glob.glob("./*.json"): with open(json, "r", encoding="utf8") as f: content = f.read() common.write("{} (\n{}\n)\n".format(os.path.basename(json), content)) #splitting code // split.py with open("merged.json", "r", encoding="utf8") as common: for line in common: name = line[:line.find(" (")] text = line[line.find(" ("):line.rfind(")")] with open(name, "w") as f: f.write(text) merge.py works good, but when I run split.py after merging the files I'm getting this error: split.py, line 8, in <module> with open(name, "w") as f: OSError: [Errno 22] Invalid argument: ' "Language": "en",' The merged .json file looks like this: ( ) TEXTFILE1.JSON ( [ { "Language": "en", "String": aaaaaa" }, { "Language": "fr", "String": "xxxxxxxx" }, ] ) TEXTFILE2.JSON ( [ { "Language": "en", "String": cccccccc" }, { "Language": "fr", "String": "bbbbb" }, ] )
Editor is loading...