473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Python API : constant variables & sub module creation

mg
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
Jul 18 '05 #1
0 1303

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
5
by: robert | last post by:
Turning algs for old NumPy modules into numpy code I suffer from this: Upon further processing of returns of numpy calculations, lots of data in an apps object tree will become elementary numpy...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.