Closed longerlsx closed 5 years ago
I was trying to get a new instance from a python class Test. However, it returns nil when I called PyInstance_New() function. Here is my testing code.
// hello.py class Test(object): def __init__(self, name): print(name) def hello(self, line): return line // test.go func init() { err := python.Initialize() if err != nil { panic(err.Error()) } } func main() { hello := python.PyImport_ImportModule("hello") if hello == nil { log.Fatalf("could not import 'hello'\n") } testGetter := hello.GetAttrString("Test") if testGetter == nil { log.Fatalf("could not retrieve 'hello.Test'") } gostr := "here is a test" pystr := python.PyString_FromString(gostr) test := python.PyInstance_New(testGetter, pystr, nil) if test == nil { // log fail at here log.Fatalf("could not retrieve 'test'") } }
Is the way I called function is wrong? How could I get a new instance from python? Thanks.
Hi, how did you resolve this issue? thanks.
I was trying to get a new instance from a python class Test. However, it returns nil when I called PyInstance_New() function. Here is my testing code.
Is the way I called function is wrong? How could I get a new instance from python? Thanks.