Extending Python by Adding Keywords & Data types

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Aug 1 02:15:28 EDT 2007


On Wed, 01 Aug 2007 01:42:38 +0000, Maximus Decimus wrote:

> Since, I am an amateur in using python, could you please be more
> specific. For new data types, you had asked to implement the classes.
> I intend to use C for implementing these data types. So where do i
> need to implement these classes ie under which file or module in the
> python package.

Like Ben Finney said, first do something about the amateur status and work
through the tutorial.

Everything in Python is an object.  And classes are a way to define
templates for new objects.  After you know classes better, ask yourself
how you would implement the already existing data types with classes
yourself and then you'll get an idea how to create new data types.

If you want to implement new types in C there's a tutorial in the docs
called “Extending and Embedding” and a reference of the Python/C API.

But maybe you should start with implementing them in Python and only
convert those parts to C code that are *really* to slow in the prototype. 
Really means measure and don't guess.

A nice step between Python and C is Pyrex, a Python-like language with some
restrictions but also C data types.  Pyrex is then translated to C and can
be compiled as Python extension module.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list