Another Pyrex Question

François Pinard pinard at iro.umontreal.ca
Sat Mar 15 09:44:53 EST 2003


[Ganesan R]

> Here width and height are attributes of Shrubbery.  Is it possible to
> setup a class variable?

Hi!  I do not know about class variables.  On the same road, I never tried
subclassing an extension type in Pyrex.

I would merely use a global variable to get the effect of a class variable.
When one writes Pyrex, one has to think assembler (or C!) a bit.  Pyrex is
the good tool for establishing a compromise between Python elegance and C
speed, so I'm also ready to think in "compromise mode" when using it.

> By the way, Pyrex is simply amazing.

Pyrex is really, undoubtedly a wonderful tool.

If we want the feel that we deeply understand the relation between the Pyrex
special constructs and the speed we can get from them, we have to get used
to the exact meaning of these constructs, and look at the generated C code
once in a while.  That's easy and that's worth.  Moreover, I surely learned
many good things about Python internals by using Pyrex as a teacher. :-)

One nice possibility of Pyrex, which is not documented enough in my opinion,
is its capabilities for embedding Python within what would otherwise be a
pure C application.  I sometimes abuse this feature to static link in view
of `gdb' debugging, by writing the main() and test() functions directly in
Pyrex -- could have been C just as well! -- and through some Makefile magic.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list