Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 91d8601

Browse files
committed
tests: add more module example
The previous CL showed how to use `cPickle.dumps`. Also show how to use `cPickle.loads`. Fixes #29
1 parent 3c15159 commit 91d8601

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,16 @@ func main() {
3434
fmt.Printf("cPickle.dumps(%s) = %q\n", gostr,
3535
python.PyString_AsString(out),
3636
)
37+
loads := pickle.GetAttrString("loads")
38+
if loads == nil {
39+
panic("could not retrieve 'cPickle.loads'")
40+
}
41+
out2 := loads.CallFunctionObjArgs("O", out)
42+
if out2 == nil {
43+
panic("could not load back out")
44+
}
45+
fmt.Printf("cPickle.loads(%q) = %q\n",
46+
python.PyString_AsString(out),
47+
python.PyString_AsString(out2),
48+
)
3749
}

0 commit comments

Comments
 (0)