473,385 Members | 1,359 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,385 software developers and data experts.

embedding python: simulating sequence get item / set item methods

Hello,

when embedding python: how can I create a type which simulates item
getters and setters? Something like this:

void setter(PyObject* self, int i, PyObject new_value)
{
// do something
}

PyObject* getter(PyObject* self, int i)
{
// do something
return something;
}

and I'd like the first method called if (from a python script):

my_list[i] = value

and the second method, if accessing the list

print str(my_list[i])

Is this possible?

--
Johannes
Jan 17 '06 #1
1 2105
Johannes Zellner <jo******@zellner.org> wrote:
Hello,

when embedding python: how can I create a type which simulates item
getters and setters? Something like this:

void setter(PyObject* self, int i, PyObject new_value)
{
// do something
}

PyObject* getter(PyObject* self, int i)
{
// do something
return something;
}

and I'd like the first method called if (from a python script):

my_list[i] = value

and the second method, if accessing the list

print str(my_list[i])

Is this possible?


Sure, see the details at <http://docs.python.org/api/newTypes.html> and
consider that what you want will need to go into a PyMappingMethods or
PySequenceMethods structure -- not well documented online, but just take
a look in the Python sources at the way the type objects for lists &c
are defined, and take it from there.
Alex
Jan 17 '06 #2

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

Similar topics

0
by: jordi | last post by:
Hi, I'm starting to use Python embedded in a C program. I'm using Python to execute several scripts using as a variables information retrieved for several multithread "agents" written in C. ...
0
by: Atul Kshirsagar | last post by:
I am embedding python in my C++ application. I am using Python *2.3.2* with a C++ extention DLL in multi-threaded environment. I am using SWIG-1.3.19 to generate C++ to Python interface. Now to...
23
by: Simon Wittber | last post by:
For the first time, I have been bitten by Python. The below code produces the results: False True when I initially expected the results: False False It took me a while to work out that...
1
by: Tommy Nordgren | last post by:
I want to write an application that embeds and extends (at least) the Python and Perl interpreters. Now i want to find as much as possible about the Python tools used for extending and embedding...
105
by: Christoph Zwerschke | last post by:
Sometimes I find myself stumbling over Python issues which have to do with what I perceive as a lack of orthogonality. For instance, I just wanted to use the index() method on a tuple which does...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.