Skip to content

Commit e9f52a6

Browse files
author
g.ph
committed
update
1 parent 489a7fe commit e9f52a6

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

README.MD

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,30 @@
55

66
```
77
go get github.com/aadog/py3-go
8+
```
9+
10+
11+
### test
12+
13+
```
14+
type K struct {
15+
Doc string
16+
}
17+
18+
func (v *K) Test(self *PyObject, args *PyObject) *PyObject {
19+
fmt.Println("test")
20+
return nil
21+
}
22+
func main(){
23+
PyImport_AppendInittab("_test", func() *PyObject {
24+
return RegPyModule("_test", &K{})
25+
})
26+
cpy3.Py_SetProgramName(os.Args[0])
27+
cpy3.Py_SetPythonHome("./")
28+
cpy3.Py_Initialize()
29+
cpy3.PyRun_SimpleString(`
30+
import _test
31+
print(_test.Call('Test'))
32+
`)
33+
}
834
```

module_test.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,29 @@ package py3
22

33
import (
44
"fmt"
5+
"github.com/aadog/py3-go/cpy3"
6+
"os"
57
"testing"
68
)
79

8-
func TestCreateModule(t *testing.T) {
9-
10-
// moduleName := "test"
11-
// Import_AppendInittab(moduleName, func() *PyObject {
12-
// def := NewModuleDef(moduleName, "")
13-
// def.AddMethodDef(NewMethodDef("aa", func() {
14-
// fmt.Println("aa")
15-
// }, "", 1))
16-
// return CreateModule(def)
17-
// })
18-
// cpy3.Py_Initialize()
19-
// cpy3.PyRun_SimpleString(`
20-
//import test
21-
//`)
22-
}
23-
2410
type K struct {
2511
Doc string
2612
}
2713

2814
func (v *K) Test(self *PyObject, args *PyObject) *PyObject {
15+
fmt.Println("test")
2916
return nil
3017
}
3118
func TestRegModule(t *testing.T) {
32-
PyImport_AppendInittab("test", func() *PyObject {
33-
return RegPyModule("test", &K{})
19+
PyImport_AppendInittab("_test", func() *PyObject {
20+
return RegPyModule("_test", &K{})
3421
})
35-
fmt.Println()
22+
cpy3.Py_SetProgramName(os.Args[0])
23+
cpy3.Py_SetPythonHome("./")
24+
cpy3.Py_Initialize()
25+
cpy3.PyRun_SimpleString(`
26+
print("aaa")
27+
#import _test
28+
#print(_test.Call('Test'))
29+
`)
3630
}

0 commit comments

Comments
 (0)