2020-10-19 21:08:55

This commit is contained in:
wizardforcel
2020-10-19 21:08:55 +08:00
parent 7f63048035
commit ab0caba1f0
140 changed files with 3982 additions and 3982 deletions

View File

@@ -24,7 +24,7 @@
例子:
```
```py
{
"name": "echo",
"age": 24,
@@ -47,7 +47,7 @@
In [1]:
```
```py
import json
from pprint import pprint
@@ -73,14 +73,14 @@ info_string = """
In [2]:
```
```py
info = json.loads(info_string)
pprint(info)
```
```
```py
{u'age': 24,
u'ages for school': {u'high school': 15,
u'middle school': 9,
@@ -103,14 +103,14 @@ pprint(info)
In [3]:
```
```py
type(info)
```
Out[3]:
```
```py
dict
```
@@ -118,14 +118,14 @@ dict
In [4]:
```
```py
info_json = json.dumps(info)
print info_json
```
```
```py
{"name": "echo", "age": 24, "married": false, "ages for school": {"middle school": 9, "university": 18, "high school": 15, "primary school": 6}, "coding skills": ["python", "matlab", "java", "c", "c++", "ruby", "scala"], "hobby": ["sports", "reading"]}
```
@@ -141,7 +141,7 @@ print info_json
In [5]:
```
```py
with open("info.json", "w") as f:
json.dump(info, f)
@@ -151,13 +151,13 @@ with open("info.json", "w") as f:
In [6]:
```
```py
with open("info.json") as f:
print f.read()
```
```
```py
{"name": "echo", "age": 24, "married": false, "ages for school": {"middle school": 9, "university": 18, "high school": 15, "primary school": 6}, "coding skills": ["python", "matlab", "java", "c", "c++", "ruby", "scala"], "hobby": ["sports", "reading"]}
```
@@ -166,7 +166,7 @@ with open("info.json") as f:
In [7]:
```
```py
with open("info.json") as f:
info_from_file = json.load(f)
@@ -174,7 +174,7 @@ pprint(info_from_file)
```
```
```py
{u'age': 24,
u'ages for school': {u'high school': 15,
u'middle school': 9,
@@ -197,7 +197,7 @@ pprint(info_from_file)
In [8]:
```
```py
import os
os.remove("info.json")