使用“gopy”,如何正确地从Python传递[]字符串?

2024-10-06 08:09:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我的密码是:

func Test(websites []string) {
    fmt.Print("test")
}

我使用gopy build生成httpget.so文件

然后,我尝试在Python代码中使用这个模块httpget.so加载ans:

import httpget
print dir(httpget)

httpget.Test(["aaaa"])

但调用该函数会导致运行时的恐慌:

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

我该如何解决这个问题?你知道吗


Tags: totestgo密码stringsothreadwebsites
1条回答
网友
1楼 · 发布于 2024-10-06 08:09:58

好的,我找到路了!!23333个

哥朗

var (
    WebSites = [1]string{"aaa"}
)

在python中

import httpget
s = httpget.GetWebSites()
s[0] = "http://www.baidu.com"
httpget.Test(s)

相关问题 更多 >