Example #1
0
func pyObjToInterface(o *C.PyObject) interface{} {
	if C.myPyString_Check(o) != 0 {
		return C.GoStringN(C.PyString_AsString(o), C.int(C.PyString_Size(o)))
	} else if C.myPyInt_Check(o) != 0 {
		return int64(C.PyInt_AsLong(o))
	} else if C.myPyDict_Check(o) != 0 {
		v := make(map[interface{}]interface{})
		items := C.PyDict_Items(o)
		for i := 0; i < int(C.PyTuple_Size(items)); i++ {
			item := C.PyTuple_GetItem(items, C.Py_ssize_t(i))
			key := C.PyTuple_GetItem(item, 0)
			value := C.PyTuple_GetItem(item, 1)
			v[pyObjToInterface(key)] = pyObjToInterface(value)
		}
		C.Py_DecRef(items)
		return v
	} else if C.myPyTuple_Check(o) != 0 {
		length := int(C.PyTuple_Size(o))
		list := make([]interface{}, length)
		for i := 0; i < length; i++ {
			list[i] = pyObjToInterface(C.PyTuple_GetItem(o, C.Py_ssize_t(i)))
		}
		return list
	}
	return nil
}
Example #2
0
func (t *Tuple) Size() int64 {
	ret := C.PyTuple_Size(c(t))
	if ret < 0 {
		panic(exception())
	}
	return int64(ret)
}
Example #3
0
func (t *Tuple) Size() int {
	ret := C.PyTuple_Size(t.c())
	if ret < 0 {
		panic(exception())
	}
	return int(ret)
}
Example #4
0
// Py_ssize_t PyTuple_Size(PyObject *p)
// Take a pointer to a tuple object, and return the size of that tuple.
//
// Changed in version 2.5: This function returned an int type. This might require changes in your code for properly supporting 64-bit systems.
func PyTuple_Size(self *PyObject) int {
	return int(C.PyTuple_Size(topy(self)))
}