![]() |
|
|
|||||||
![]() |
Python - Define a constant in Python C extension |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
I'm writing a C extension for Python, is it possible to define
constants in the C code and have them visible from Python? fredbasset1000@gmail.com |
|
|
|
|
#2 |
|
Posts: n/a
|
On 2009-02-27 14:54, wrote:
> I'm writing a C extension for Python, is it possible to define > constants in the C code and have them visible from Python? In your init<module> function, create Python objects from the constants and insert them into the module using PyModule_AddObject(). The initspam() function in this section does this (though not with #defined constants): http://docs.python.org/extending/ext...tension-module -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco Robert Kern |
|
|
|
#3 |
|
Posts: n/a
|
wrote:
> I'm writing a C extension for Python, is it possible to define > constants in the C code and have them visible from Python? There's an API function to create a module-level name with a given value, e.g. PyModule_AddIntConstant (module, "S_IRUSR", S_IRUSR); // user read In this example, S_IRUSR was defined in one of the .h files for the functions being wrapped. Mel. Mel |
|
|
|
#4 |
|
Posts: n/a
|
wrote:
> I'm writing a C extension for Python, is it possible to define > constants in the C code and have them visible from Python? Have you looked at Cython? It allows you to define e.g. enums as "public" and will generate the rest for you. http://cython.org Stefan Stefan Behnel |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Which Domain Extension best | reshmaa | General Help Related Topics | 0 | 10-07-2009 09:56 AM |
| Torrent file with wrong file extension | Marc | DVD Video | 3 | 02-25-2007 04:07 AM |
| SVGA monitor extension question | SBFan2000 | A+ Certification | 6 | 12-14-2006 12:42 PM |
| DVD Verdict reviews: THE CONSTANT GARDENER, TRANSPORTER 2, and more! | DVD Verdict | DVD Video | 0 | 01-10-2006 09:21 AM |
| File Extension | Raymond | A+ Certification | 7 | 02-18-2005 01:24 AM |