Extending Python in C ?'s

Andrew Murray mr.murray at mindspring.com
Tue Sep 4 05:59:41 CEST 2001


I'm looking into writing some types in C for use in a Python program
I'm working on. I've been reading and it looks really easy (especially
with SWIG) to create a simple type in C for use in python, but does anybody
how (or can point me to a good reasource on how) to create a type in C
whose data members would be other types written in C? For instance, if I
wanted to recreate this (ficticious) type:

Class myClass():
    dataMembers = []
    def __init__(self, integer_input):
        while(i < integer_input):
            dataMembers = append(myOtherClass("hello from # " + str(i))
    def printMessages(self):
        for member in self.dataMembers:

Class myOtherClass():
    message = ''
    def __init__(self, string_input):
        self.message = string_input
    def printMessage(self):
        print self.message

I hope this example is clear... Please advise


Andrew Murray

More information about the Python-list mailing list