473,795 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class constant for extension

Hi,

I have written a small prototype Python extension for a C-library.

I have the methods all sorted out and it is working fine.

In the C-library, they are various constants of types like string,
integer, float and matrix. I'd like to expose them as READONLY values.

Is the use of PyMemberDefs a suitable way to provide such access?

I'd like the user of the extension to be able to do something like
the follow

import MyExtension

MyExtension.beg in()
mv = MyExtension.min Value
MyExtension.pro cess(MyExtensio n.versionStr)
MyExtension.end ()

Is someone able to point me to an example code of how I can write my
extension so that the references to those constants can be used in the
above way.

Regards

Dec 19 '06 #1
1 1684
Yu**********@gm ail.com wrote:
Hi,

I have written a small prototype Python extension for a C-library.

I have the methods all sorted out and it is working fine.

In the C-library, they are various constants of types like string,
integer, float and matrix. I'd like to expose them as READONLY values.

Is the use of PyMemberDefs a suitable way to provide such access?

I'd like the user of the extension to be able to do something like
the follow

import MyExtension

MyExtension.beg in()
mv = MyExtension.min Value
MyExtension.pro cess(MyExtensio n.versionStr)
MyExtension.end ()

Is someone able to point me to an example code of how I can write my
extension so that the references to those constants can be used in the
above way.

Regards
A couple of years ago I wanted to do something similar for a project I
was working on.
Below is a snippet of some sample C code from the module's
initialization function which should give you an idea of the approach
used. It's a limited example and only creates module identifiers for
simple integer values, not the more complex types you are interested
in, nor does it do anything to make them read only, but it might help
get you started.

If you find something that addresses these deficiencies, please post
your findings.

Best,
-Martin

// snippet
#include "Python.h"

enum METAtags
{
kMETA_MojikumiX 4051 = 0,
kMETA_UNIUnifie dBaseChars = 1,
kMETA_BaseFontN ame = 2
}

void initPyExtension ()
{
PyObject *m, *d, *o;
m = Py_InitModule4( "PyExtensio n", pyis_methods,
PySING_module_d ocumentation,
(PyObject*)NULL , PYTHON_API_VERS ION);

// Add some symbolic constants to the module
d = PyModule_GetDic t(m); // get modules dictionary

PyObject* o = PyInt_FromLong( kMETA_MojikumiX 4051);
PyDict_SetItemS tring(d, "idMojikumiX405 1", o);
Py_INCREF(o); // for dictionary ref

PyObject* o = PyInt_FromLong( kMETA_UNIUnifie dBaseChars);
PyDict_SetItemS tring(d, "idUNIUnifiedBa seChars", obj);
Py_INCREF(o);

PyObject* o = PyInt_FromLong( kMETA_BaseFontN ame);
PyDict_SetItemS tring(d, "idBaseFontName ", obj);
Py_INCREF(o);
Dec 24 '06 #2

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

Similar topics

6
35677
by: fctk | last post by:
hello, i'm trying to compile this small program: int main(void) { unsigned long int max; max = 4000000000;
3
20878
by: johnmmcparland | last post by:
Hi all, I would like to have a static constant array inside a class definition which would contain the number of days in each month (I am writing a Date class as an exercise). However my attempts so far have been unsuccessful. Take this Test class as an example // test.hpp
9
2830
by: Justin Voelker | last post by:
I have a configuration file that contains the host, username, password, and database name required for any database connections. The config file runs through a few if/then/else statements to determine if the website is local or remote and if it is local if it is the test site or "live" site then it sets the 4 variables. I am trying to implement a webstats package that has it's own config file. I would the new config file to be able to use...
9
8896
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've *defined* "x"'s value to be 10, isn't above statement a
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.