Comments (2)
hi,
could you give some more informations about you are trying to achieve?
the following might help, if you want to simply pickle a python object:
package main
import (
"fmt"
"github.com/sbinet/go-python"
)
func init() {
err := python.Initialize()
if err != nil {
panic(err.Error())
}
}
func main() {
gostr := "foo"
pystr := python.PyString_FromString(gostr)
str := python.PyString_AsString(pystr)
fmt.Println("hello [", str, "]")
pickle := python.PyImport_ImportModule("cPickle")
if pickle == nil {
panic("could not import 'cPickle'")
}
dumps := pickle.GetAttrString("dumps")
if dumps == nil {
panic("could not retrieve 'cPickle.dumps'")
}
out := dumps.CallFunctionObjArgs("O", pystr)
if out == nil {
panic("could not dump pystr")
}
fmt.Printf("cPickle.dumps(%s) = %q\n", gostr,
python.PyString_AsString(out),
)
}
which gives:
$ go run ./main.go
hello [ foo ]
cPickle.dumps(foo) = "S'foo'\np1\n."
from go-python.
Thank you very much
from go-python.
Related Issues (20)
- Does it works on Centos7 i686 system? HOT 1
- go get report errors HOT 4
- panic when register callback from go into python as module HOT 1
- How to call a function of Go from python HOT 3
- After running go-python script for a while, the memory becomes larger and larger HOT 1
- How to build the environment required by go-golang under window
- panic when run multi goroutine HOT 3
- Error reporting for execute command under win10 HOT 3
- Hi,
- Question: Usable with WebAssembly (WASM)? HOT 1
- Documentation not displayed due to license restrictions. HOT 2
- Pandas and go Python are incompatible? HOT 9
- D:\go\project\src\github.com\sbinet\go-python\capi.go:33:32: could not determine kind of name for C.METH_OLDARGS
- Exception SystemError: '/builddir/build/BUILD/Python-2.7.5/Objects/classobject.c:521: bad argument to internal function'
- can i import python module like selenium to use inside golang code?
- Let's try it, python bindings cgo-less HOT 1
- Cannot pass Integer type to CallFunction
- go panic when multi thread HOT 1
- How to use cPickle loads or dump complicated data, like array, class object
- memory leak๏ผ HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-python.