Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python API : constant variables & sub module creation

Reply
Thread Tools

Python API : constant variables & sub module creation

 
 
mg
Guest
Posts: n/a
 
      09-28-2004
Hi everybody...

I am using Python API in order to create bindings.
So, in the init function of my module, I create constants :

PyMODINIT_FUNC initMyModule( void )
{
PyObject* module = Py_InitModule3( "MyModule", 0, "this is my
module" ) ;
if( ! module ) return ;

PyObject* dict = PyModule_GetDict( module ) ;
if( ! dict ) return ;

long value = 0 ; // for the example
PyObject* py_value = PyInt_FromLong( value ) ;
char* name = "NULL" ;
PyDict_SetItemString( dict, name, py_value ) ;
Py_DECREF( py_value ) ;
}

So, my first "problem" is that my module variable is mutable; I can
write the following instruction in python :

>>> import MyModule
>>> null = MyModule.NULL
>>> print null

0
>>> MyModule.NULL = 99
>>> null = MyModule.NULL
>>> print null

99

Then, my question is : how can I implement a constant variable from the
API ?

My second problem is that I would like implement my NULL variable in a
sub module of my module in order to write the follow python syntax :

>>> import MyModule
>>> null = MyModule.MySubModule.NULL
>>> print null

0

Then, my question is : how can I do it ?

Thanks a lot,
Mathieu
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Death To Sub-Sub-Sub-Directories! Lawrence D'Oliveiro Java 92 05-20-2011 06:50 AM
no module api file after generating ruby core api Bob Lu Ruby 0 06-25-2009 03:07 AM
Recognising Sub-Items and sub-sub items using xslt Ben XML 2 09-19-2007 09:35 AM
Calling the C API from Python and Python program from same C API -bidirectional Praveen, Tayal (IE10) Python 0 03-17-2005 06:33 AM
PYTHON API : add new classes in a module from an other module mathieu gontier Python 1 09-01-2004 12:35 PM



Advertisments