Seite 1 von 1

python c api: "konstanten"

Verfasst: Montag 7. Mai 2007, 12:03
von menno
Hallo,

nachdem mein PyInstaller Problem gelöst ist, hier noch eine andere Frage.
Wie kann ich per C API 'Enumerationen' generieren, die ich in Python in der Art Modul.Enum1, Modul.Enum2, ... ansprechen kann?

Bisher sieht mein sehr einfaches C-API-Modul (HW-API-Wrapper) gekürzt wie folgt aus:

Code: Alles auswählen

//------------------------------------------------------------------------------
#include "Python.h"
#include "api.h"
//------------------------------------------------------------------------------
static PyObject* WrapperApiInit(PyObject *self, PyObject *args) {
  if(! PyArg_ParseTuple(args, "") ) {
    PyErr_SetString(error, "Error: apiInit Arguments");
    return NULL;
  }
  return Py_BuildValue( "h", apiInit() );
}
//------------------------------------------------------------------------------
static PyObject* WrapperApiBreak(PyObject *self, PyObject *args) {
  if(! PyArg_ParseTuple(args, "") ) {
    PyErr_SetString(error, "Error: apiBreak Arguments");
    return NULL;
  }
  apiBreak();
  return Py_BuildValue( "h", 0 );
}
//------------------------------------------------------------------------------
static PyMethodDef apiMethods[] = {
{"apiInit",  WrapperApiInit,    METH_VARARGS},
{"apiBreak", WrapperApiBreak, METH_VARARGS},
{NULL, NULL} }
//------------------------------------------------------------------------------
void WrapperApi(void) {
  Py_InitModule( "WrapperApi", apiMethods );
}
//------------------------------------------------------------------------------
Aus der Dokumentation der C-API für Python bin ich nicht sehr schlau geworden. Wie kann ich Enums (oder auch Konstanten) integrieren?

Vielen Dank
Menno

Verfasst: Mittwoch 9. Mai 2007, 08:10
von menno
mmh.
keiner eine idee?

menno

Verfasst: Mittwoch 9. Mai 2007, 08:42
von Rebecca
Schau dir mal das hier an: http://docs.python.org/api/moduleObjects.html. Und hier ein Beispiel mit Integer-Konstanten.

Verfasst: Mittwoch 9. Mai 2007, 10:43
von menno
Super. Funktioniert.
Wer hätte gedacht das das so einfach ist :o)

Menno