[Pyrex] Wish: from foo cimport *

John J Lee jjl at pobox.com
Mon Jul 21 19:45:52 CEST 2003


John wrote:
> This makes me think of...

The 'this' in question was this message, which I forgot I hadn't posted
yet.

I hardly ever use import * in Python.  However, in Pyrex, it seems it
would be very useful.  I have a huge list of cdefs in my .pyx file, which
I'd like to shovel into a .pxd.  If I do that, though, I'd have to rewrite
all my C symbols with some prefix, where I'd much prefer to import them
unqualified:

1. I find this form hard to read, because of all the foo's (my C symbols
have a common prefix anyway, which is often the case when wrapping C
libraries):

cimport foo

cdef class Foo:
    cdef foo.symbola
    cdef foo.symbolb

    def __new__(self, *args, **kwargs):
...


2. And this form is worse than useless for my particular use of it (I'd
like to use the cimport mechanism precisely to get rid of a huge chunk of
boilerplate cdefs from my .pyx, so I don't want to *add* a huge chunk of
boilerplate imports to that):

from foo cimport symbola
from foo cimport symbolb

cdef class Foo:
    cdef foo.symbola
    cdef foo.symbolb

    def __new__(self, *args, **kwargs):
...


So I'd like to do:

3.

from foo cimport *

cdef class Foo:
    cdef symbola
    cdef symbolb

    def __new__(self, *args, **kwargs):
...


The single circumstance where I use from foo import * in Python is when
I'm using PyQt.  There, there are a big bunch of classes, and they all
start with the prefix 'Q': QWidget, QLineEdit, etc.  The same tends to be
true of C symbols -- there are lots of them you want to import when
wrapping a library, and they usually start with a common prefix (or
prefixes).


John





More information about the Pyrex mailing list