Python API : constant variables & sub module creation

Discussion in 'Python' started by mg, Sep 28, 2004.

  1. mg

    mg Guest

    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
    mg, Sep 28, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mathieu gontier
    Replies:
    1
    Views:
    314
    Alex Martelli
    Sep 1, 2004
  2. Ben
    Replies:
    2
    Views:
    864
  3. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    1,974
    Lawrence D'Oliveiro
    May 20, 2011
  4. Bob Lu
    Replies:
    0
    Views:
    116
    Bob Lu
    Jun 25, 2009
  5. sm
    Replies:
    3
    Views:
    98
    Dave Weaver
    Jan 4, 2007
Loading...

Share This Page