Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
/go-pythonPublic archive

naive go bindings to the CPython2 C-API

License

NotificationsYou must be signed in to change notification settings

sbinet/go-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sbinet/go-python only supports CPython2. CPython2 isn't supported anymore bypython.org. Thus,sbinet/go-python is now archived.A possible alternative may be to use and contribute togo-python/cpy3 instead.

Build StatusBuild statusGoDocs

Naivego bindings towards the C-API of CPython-2.

this package provides ago package named "python" under which most of thePyXYZ functions and macros of the public C-API of CPython have been exposed.

theoretically, you should be able to just look at:

http://docs.python.org/c-api/index.html

and know what to type in yourgo program.

this package also provides an executable "go-python" which just loads "python" and then callpython.Py_Main(os.Args).the rational being that under such an executable,go based extensions for C-Python would be easier to implement (as this usually means calling intogo fromC through some rather convoluted functions hops)

Install

WithGo 1 and thego tool,cgo packages can't pass anymoreadditionalCGO_CFLAGS from external programs (exceptpkg-config)to the "fake"#cgo preprocessor directive.

go-python now usespkg-config to get the correct location ofheaders and libraries.Unfortunately, the naming convention for thepkg-config package isnot standardised across distributions and OSes, so you may have toedit thecgoflags.go file accordingly.

 $ go get github.com/sbinet/go-python

Ifgo get +pkg-config failed:

 $cd go-python $ edit cgoflags.go $ make VERBOSE=1

Note: you'll need the proper header andpython development environment. On Debian, you'll need to install thepython-all-dev package

Documentation

Is available ongodocs:

https://godocs.io/github.com/sbinet/go-python

Example:

package mainimport"fmt"import"github.com/sbinet/go-python"funcinit() {err:=python.Initialize()iferr!=nil {panic(err.Error())   } }funcmain() {gostr:="foo"pystr:=python.PyString_FromString(gostr)str:=python.PyString_AsString(pystr)fmt.Println("hello [",str,"]")}
$ go run ./main.gohello [ foo ]

TODO:

  • fix handling of integers (I did a poor job at making sure everything was ok)

  • add CPython unit-tests

  • do not exposeC.FILE pointer and replace it withos.File in "go-python" API

  • provide an easy way to extend go-python withgo based extensions

  • think about the need (or not) to translate CPython exceptions into go panic/recover mechanism

  • use SWIG to automatically wrap the whole CPython api ?

About

naive go bindings to the CPython2 C-API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors11

Languages


[8]ページ先頭

©2009-2025 Movatter.jp