☰
-
Php 95
-
Java 94
-
Javascript 37
-
Regex 18
-
Git 17
-
Security 16
-
Docker 07
-
Python 58
-
Machine Learning 14
-
Book Highlights
Python
/
Storage
- 1 Language 9
-
Hello World S
-
Variables S
-
Functions S
-
Conditional A S
-
Operators S
-
While S
-
Turtle S
-
Script Mode S
-
Debugging S
- 2 Strings 7
-
Slice S
-
Raw Strings S
-
Regex A S
-
Validation S
-
Config S
-
Security S
-
Encrypt A S
- 3 Collections 5
-
Lists S
-
Dictionaries S
-
Efficiency S
-
Tuples S
-
References S
- 4 Functions 5
-
Recursion S
-
Factorial S
-
Modulus S
-
Reassignment S
-
Approximate S
- 5 Storage 8
-
Files S
-
Databases S
-
Pipes S
-
With open S
-
Shelve A S
-
Zip S
-
Csv S
-
Json S
- 6 Class 4
-
Definition S
-
Attributes S
-
Functional S
-
Methods S
- 7 Goodies 5
-
Conditional Expression S
-
List Comprehension S
-
Generator S
-
Named Tuple S
-
Modules S
- 8 Applications 5
-
Pythagora A S
-
Palindrome A S
-
Binary Search A S
-
Conway Game A S
-
Coin Flip A S
- 9 Scheduler 4
-
Time S
-
Multithreading A S
-
Subprocess S
-
Logging S
- 10 Packages 6
-
Clipboard A S
-
Ocr A S
-
Socket S
-
Image S
-
Virtualenv S
-
Jupyter S
S
R
Q
Read
p381 Python json module translates json to Python values.
"""Json read:
Json string always uses double quotes.
The loads() methods return json as a Python dictionary.
The loads() method means 'load string' not 'loads'
"""
import json
str = '{"name":"John", "age":40, "job":null}'
dict = json.loads(str)
assert dict.get('name') == 'John'
assert dict.get('age') == 40
assert dict.get('job') == None
Write
The dump() method translates Python value into a json string.
"""Json write:
The method dumps() mean 'dump string' not 'dumps'
"""
import json
dict = {"name":"John", "age":40, "job":None}
json = json.dumps(dict)
assert json == '{"name": "John", "age": 40, "job": null}'
assert json != {"name": "John", "age": 40, "job": None}
assert json != '{"name": "John", "age": 40, "job": None}'
➥ Questions
Last update: 69 days ago