Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
/go-pythonPublic archive

Commit3c15159

Browse files
committed
tests: add module import example
Add a simple example on how to import and use `cPickle` from `go-python`.Updates#29.
1 parent7991d39 commit3c15159

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎tests/main.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
56
"github.com/sbinet/go-python"
67
)
78

@@ -17,4 +18,20 @@ func main() {
1718
pystr:=python.PyString_FromString(gostr)
1819
str:=python.PyString_AsString(pystr)
1920
fmt.Println("hello [",str,"]")
21+
22+
pickle:=python.PyImport_ImportModule("cPickle")
23+
ifpickle==nil {
24+
panic("could not import 'cPickle'")
25+
}
26+
dumps:=pickle.GetAttrString("dumps")
27+
ifdumps==nil {
28+
panic("could not retrieve 'cPickle.dumps'")
29+
}
30+
out:=dumps.CallFunctionObjArgs("O",pystr)
31+
ifout==nil {
32+
panic("could not dump pystr")
33+
}
34+
fmt.Printf("cPickle.dumps(%s) = %q\n",gostr,
35+
python.PyString_AsString(out),
36+
)
2037
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp