[Pyrex] A simple question: rephrased

Adapted Cat a.c.junker at gmail.com
Wed Apr 18 10:55:32 UTC 2007


Anything declared / imported with a "cdef" is a C variable, and thus
will not be visible to Python. If you need to access them from Python,
you'll need to declare Python variables instead. I have run into this
problem myself, and it is annoying to have to duplicate everything
(just makes more work for you when the header file changes) but
AFAIK this is the only way that works. E.g.:

# Declare const1 and const2, renaming them to avoid conflicts.
cdef extern from "someheader.h":
    c_const1 "const1"
    c_const2 "const2"

# Declare Python objects to hold copies of the C variables.
const1 = c_const1
const2 = c_const2

Hope this helps!

On 4/18/07, Alain Pointdexter <alainpoint at yahoo.fr> wrote:
> Hi,
> Thanks for all who answered.
> But i expressed myself in a wrong way.
> My question was:
> i know how to access constants or defines from within pyrex file.
> Just use an anonymous enum:
> cdef enum:
>     const1
>     const2
>
> But how do you access those constants defined in   pyrex file FROM PYTHON.
>
>
> Regards
>
> Alain
>
>
>
>
> ___________________________________________________________________________
> Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions !
> Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses
> http://fr.answers.yahoo.com
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex
>



More information about the Pyrex mailing list