我的Go代码是:
func Test(websites []string) {
fmt.Print("test")
}
我使用
gopy build
生成httpget.so
文件然后,我尝试在我的Python代码中使用此模块
httpget.so
加载ans:import httpget
print dir(httpget)
httpget.Test(["aaaa"])
但是调用该函数会导致Go方面出现恐慌:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x103998688]
goroutine 17 [running, locked to thread]:
main.cgo_func_httpget_Test(0x1)
/private/var/folders/yg/tx1wr1c5233fd299lpqnvjy40000gn/T/gopy-066392802/httpget.go:173 +0x18
goroutine 18 [syscall, locked to thread]:
runtime.goexit()
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/asm_amd64.s:1696 +0x1
我应该如何解决这个问题?
最佳答案
好吧,我找到路了! 23333
高朗
var (
WebSites = [1]string{"aaa"}
)
在python中
import httpget
s = httpget.GetWebSites()
s[0] = "http://www.baidu.com"
httpget.Test(s)
关于python - 使用`gopy`,如何正确地将[]字符串从Python传递到Go?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33759003/