py

package module
v0.0.0-...-adb74cb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2015 License: BSD-3-Clause Imports: 1 Imported by: 1

README

py

py is a high-level API wrapping the low-level CPython C-API, for go.

Installation

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

Documentation

Documentation is available on godoc:

github.com/go-python/py

Examples

package main

import (
	"fmt"

	"github.com/go-python/py"
)

func init() {
	err := py.Initialize()
	if err != nil {
		panic(err)
	}
}

func main() {
	gostr := "foo"
	pystr := py.NewString(gostr)
	fmt.Printf("hello [%v]\n", pystr)
}
$ go run ./main.go
hello [foo]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dict

type Dict interface {
	// Clear empties an existing dictionay of all key-value pairs.
	Clear()

	// Contains determines whether a dictionary contains the key k
	Contains(k Object) bool

	// SetItem inserts the value v into the dictionary with a key k
	SetItem(k, v Object) error

	// DelItem removes the entry with key k from the dictionary
	DelItem(k Object) error

	// GetItem returns the object with key from the dictionary
	GetItem(k Object) (Object, error)

	// Items returns all the items from the dictionary
	Items() [][2]Object

	// Keys returns all the keys from the dictionary
	Keys() []Object

	// Values returns all the values from the dictionary
	Values() []Object

	// Size returns the number of items in the dictionary
	Size() int
}

Dict represents the python dict-like protocol

type Object

type Object interface {
	// Increment the reference count.
	// The Object may be nil, in which case the function has no effect.
	IncRef()

	// Decrement the reference count.
	// If the Object is nil, nothing happens.
	DecRef()

	// HasAttr returns whether this object has an attribute with name 'n'
	HasAttr(n string) bool

	// GetAttr returns the attribute with name 'n'
	GetAttr(n string) (Object, error)

	// SetAttr sets the value of the attribute named 'n' of the object to the value 'v'
	SetAttr(n string, v Object) error

	// DelAttr deletes the attribute named 'n' of the object
	DelAttr(n string) error

	String() string

	// Call calls a callable Object with args as arguments
	Call(args ...Object) (Object, error)

	// Hash computes and returns the hash value of an Object
	// On failure, Hash returns -1.
	Hash() int64

	// Type returns the Type of this Object.
	Type() Object
}

Object represents any Python object and codifies the Python object protocol.

func New

func New(v interface{}) Object

New creates a new py.Object value from a Go value

Directories

Path Synopsis
_examples