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

@@ -8,7 +8,7 @@
In [1]:
```
```py
try:
import cPickle as pickle
except:
@@ -22,7 +22,7 @@ except:
In [2]:
```
```py
data = [ { 'a':'A', 'b':2, 'c':3.0 } ]
data_string = pickle.dumps(data)
@@ -34,7 +34,7 @@ print data_string
```
```
```py
DATA:
[{'a': 'A', 'c': 3.0, 'b': 2}]
PICKLE:
@@ -54,14 +54,14 @@ sa.
In [3]:
```
```py
data_from_string = pickle.loads(data_string)
print data_from_string
```
```
```py
[{'a': 'A', 'c': 3.0, 'b': 2}]
```
@@ -78,12 +78,12 @@ print data_from_string
In [4]:
```
```py
print pickle.HIGHEST_PROTOCOL
```
```
```py
2
```
@@ -92,7 +92,7 @@ print pickle.HIGHEST_PROTOCOL
In [5]:
```
```py
data_string_1 = pickle.dumps(data, 1)
print "Pickle 1:", data_string_1
@@ -103,7 +103,7 @@ print "Pickle 2:", data_string_2
```
```
```py
Pickle 1: ]q<EFBFBD>}q<EFBFBD>(U<EFBFBD>aU<EFBFBD>AU<EFBFBD>cG@<EFBFBD>U<EFBFBD>bK<EFBFBD>ua.
Pickle 2: <EFBFBD><EFBFBD>]q<EFBFBD>}q<EFBFBD>(U<EFBFBD>aU<EFBFBD>AU<EFBFBD>cG@<EFBFBD>U<EFBFBD>bK<EFBFBD>ua.
@@ -113,12 +113,12 @@ Pickle 2: <20><>]q<>}q<>(U<>aU<61>AU<41>cG@<40>U<EFBFBD>bK<62>ua.
In [6]:
```
```py
print pickle.dumps(data, -1)
```
```
```py
<EFBFBD><EFBFBD>]q<EFBFBD>}q<EFBFBD>(U<EFBFBD>aU<EFBFBD>AU<EFBFBD>cG@<EFBFBD>U<EFBFBD>bK<EFBFBD>ua.
```
@@ -127,13 +127,13 @@ print pickle.dumps(data, -1)
In [7]:
```
```py
print "Load 1:", pickle.loads(data_string_1)
print "Load 2:", pickle.loads(data_string_2)
```
```
```py
Load 1: [{'a': 'A', 'c': 3.0, 'b': 2}]
Load 2: [{'a': 'A', 'c': 3.0, 'b': 2}]
@@ -152,7 +152,7 @@ Load 2: [{'a': 'A', 'c': 3.0, 'b': 2}]
In [8]:
```
```py
with open("data.pkl", "wb") as f:
pickle.dump(data, f)
@@ -162,7 +162,7 @@ with open("data.pkl", "wb") as f:
In [9]:
```
```py
with open("data.pkl") as f:
data_from_file = pickle.load(f)
@@ -170,7 +170,7 @@ print data_from_file
```
```
```py
[{'a': 'A', 'c': 3.0, 'b': 2}]
```
@@ -179,7 +179,7 @@ print data_from_file
In [10]:
```
```py
import os
os.remove("data.pkl")