-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyjson.py
35 lines (34 loc) · 1.3 KB
/
pyjson.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import json
def pywrite(jsonpy, filename = "dynampy.py"):
# test = {"def fun():": {"value": "1", "print(": "'test',value)"}}
with open(filename, "w", encoding="utf-8") as f:
json.dump(jsonpy, f, ensure_ascii=False, indent=4)
pyjson = ""
with open(filename, "r", encoding="utf-8") as f:
content = ''
for line in f.readlines():
content = content + line[4:]
pyjson = (
content.replace("{in_curly}", "__open_currly__")
.replace("{fin_curly}", "__close_currly__")
.replace("{is}", "__colon__")
.replace("{with}", "__camma__")
.replace("{nextline}","__next_line__")
.replace("{tab}", " ")
.replace("{quote}", "__single_quote__")
.replace("{", "")
.replace("}", "")
.replace("(:", "(")
.replace(":", "")
.replace('"', "")
.replace("'", '"')
.replace(",\n", "\n")
.replace("__single_quote__","'")
.replace("__colon__", ":")
.replace("__open_currly__", "{")
.replace("__close_currly__", "}")
.replace("__camma__", ",")
.replace("__next_line__ ", "\\")
)
with open(filename, "w", encoding="utf-8") as f:
f.write(pyjson)