Created
April 23, 2012 20:29
-
-
Save saghul/2473614 to your computer and use it in GitHub Desktop.
PyStructSequence usage example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf8 | |
from distutils.core import setup, Extension | |
setup(name = "foo", | |
version = "0.0.1", | |
author = "Saúl Ibarra Corretgé", | |
author_email = "[email protected]", | |
description = "PyStructSequence example", | |
ext_modules = [Extension('foo', | |
sources = ['test_pystructsequence.c'], | |
)] | |
) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Python.h" | |
#include "structmember.h" | |
#include "structseq.h" | |
static PyTypeObject FooResultType = {0, 0, 0, 0, 0, 0}; | |
static PyStructSequence_Field foo_result_fields[] = { | |
{"field_1", "This is field 1"}, | |
{"field_2", "This is field 2"}, | |
{"field_3", "This is field 3"}, | |
{NULL} | |
}; | |
static PyStructSequence_Desc foo_result_desc = { | |
"foo_result", | |
NULL, | |
foo_result_fields, | |
3 | |
}; | |
PyMODINIT_FUNC | |
initfoo(void) | |
{ | |
PyObject *foo = Py_InitModule("foo", NULL); | |
if (FooResultType.tp_name == 0) | |
PyStructSequence_InitType(&FooResultType, &foo_result_desc); | |
Py_INCREF((PyObject *) &FooResultType); | |
PyModule_AddObject(foo, "foo_result", (PyObject *) &FooResultType); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment