473,657 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

python wrapper question

Hello, I am trying to create a wrapper for a function with the following
prototype:
int ap_get_playlist (int session, int *argc, char ***the_list);
I'm not quite sure how to construct the Py_BuildValue. I would like the
python function to return a list of strings. However, the length of the
list, (*argc in the function call), will vary at run time. Is it
possible to have a wrapper function return a list whose size is not know
at compile time? Thanks for any suggestions. -Garett

Jul 18 '05 #1
1 1363
On Mon, 26 Jul 2004, Garett Shulman wrote:
Hello, I am trying to create a wrapper for a function with the following
prototype:
int ap_get_playlist (int session, int *argc, char ***the_list);
I'm not quite sure how to construct the Py_BuildValue. I would like the
python function to return a list of strings. However, the length of the
list, (*argc in the function call), will vary at run time. Is it
possible to have a wrapper function return a list whose size is not know
at compile time? Thanks for any suggestions. -Garett


You will have to construct the list manually, using PyList_New(argc ) to
make a new list of the correct size, PyString_FromSt ring(...) for each
item to make a string out of it, and PyList_SET_ITEM (...) to store each
item into the list. You can then pass the resulting list to Py_BuildValue
as an "O" type.

Alternatively, you can wrap the above list-building goo in a function
that accepts a char ** and returns a PyObject *, and then use the magic
"O&" type in Py_BuildValue, passing it first your list-building function
and then the string array.

Hope this all made some sense :P

Jul 18 '05 #2

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

Similar topics

1
4254
by: JW | last post by:
Hi, Below is a description of what I would like to do. Would someone tell me if it is possible and if so, how? I have an array (presumably 'large') that is mallocced in a C function and its values are initialized in that same function. I would like to pass just the pointer to the beginning of the array
25
2123
by: Allenabethea | last post by:
Jython is 100% java coded python. Python objects work with javacompilers and Virtual machines. I am a hobby programmer so the technical reasons are probably beyond me... Why is python incompatible with .net? Why can't python be coded in C#? I see the the MONO project on linux/unix is advancing. .Net seems to be a juggernaut especially if programmers will be able to use their favorite(most productive) language to program in. (every...
5
3174
by: John Hunter | last post by:
I have a question about what it takes to trigger GPL restrictions in python code which conditionally uses a GPL library. Here is the context of my question. matplotlib, which I develop, is a plotting module which is distributed under a PSF compatible license, and hence we avoid using GPLd code so as to not trigger the GPL requirements. matplotlib has rigid segregation between the front end (plotting commands, figure objects, etc) and...
14
2724
by: Java and Swing | last post by:
static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // this will store the result in a Python object PyObject *finalResult; // get arguments from Python char *result = 0; char *in= 0; char *aString = 0; char *bString = 0; MY_NUM *a;
2
3090
by: GinTon | last post by:
EyeDB is a free ODBMS based on the ODMG 3 specification with programming interfaces for C++ and Java. It is very powerfull, mature, safe and stable. In fact, it was developed in 1992 for the Genome View project althought rewritten in 1994, and has been used in a lot of bioinformatics projects http://www.eyedb.org/ Python does not have any programming interface to ODBMS and I believe that it would be very interesting that the Python...
3
275
by: Daniel Fetchinson | last post by:
Does Python 2.5.2's embedded SQLite support full text searching? Sqlite itself is not distributed with python. Only a python db api compliant wrapper is part of the python stdlib and as such it is completely independent of the sqlite build. In other words, if your sqlite build supports full text searching you can use it through the python sqlite wrapper (that is part of the stdlib) and if it doesn't then not. This is true for any sqlite...
0
896
by: Fuzzyman | last post by:
Hello all, Sorry - my messages aren't showing up via google groups, so I'm kind of posting on faith... Anyway, I solved my problem (I think)... import sys if sys.version_info == 3:
13
3907
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type Chinese characters, but neverthelss is unable to show them up on screen. The follow is some of the error message I received after I logged off the program: "Could not write output: <type "exceptions: UnicodeEncodeError'>, 'ascii' codec can't...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7321
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
6163
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
5632
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
4151
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
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.