Re: Help with pointers when calling from python to C

2010-10-10 Thread Nobody
On Fri, 08 Oct 2010 18:02:15 +0200, Jonas H. wrote: > On 10/08/2010 05:23 PM, Carolyn MacLeod wrote: >> "How do I pass an integer by reference to a C function?" > > That's impossible in pure Python. The only thing I can think of is a > wrapper in C. I didn't see the original message, but if you

Re: Help with pointers when calling from python to C

2010-10-08 Thread Jonas H.
On 10/08/2010 05:23 PM, Carolyn MacLeod wrote: "How do I pass an integer by reference to a C function?" That's impossible in pure Python. The only thing I can think of is a wrapper in C. -- http://mail.python.org/mailman/listinfo/python-list

Help with pointers when calling from python to C

2010-10-08 Thread Carolyn MacLeod
Hi. This is kind of a cross-product question, having to do with accessibility on Linux using ATK (AT-SPI). However, I think it really boils down to a python question: "How do I pass an integer by reference to a C function?" I am using Accerciser (http://live.gnome.org/Accerciser), an accessibi

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>>> As others already said, using a Numpy array or an array.array object >>> would >>> be more efficient (and even easier - the C code gets a pointer to an >>> array >>> of integers, as usual). >> >> I looked for this in the C API docs but couldn't find anything on how >> to make an array.array pyt

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Gabriel Genellina
En Sun, 28 Dec 2008 01:47:08 -0200, Daniel Fetchinson escribió: As others already said, using a Numpy array or an array.array object would be more efficient (and even easier - the C code gets a pointer to an array of integers, as usual). I looked for this in the C API docs but couldn't

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Ivan Illarionov
python.org/c-api/arg.htmlfrom which I learned how to pass > a fixed number of basic datatypes (int, float, string) from python to > C and back. What I don't know is how to pass an array back and forth. > > As far as I can see PyArg_ParseTuple is the function I should use for > conv

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>>> You MUST check EVERY function call for errors! >> >> Yes, I know :) >> > > Believe me, if you don't, there is a risk of crashing the program. And > they're a lot harder to find and fix. Sure, what I meant by the smiley is just that it was a quick and dirty example, not real code. In a real cod

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>> This is the function I have, the corresponding python function will >> take two equal length lists of integers and the C function will >> compute their sum and return the result as a python tuple. >> >> >> static PyObject *func( PyObject * self, PyObject * args ) >> { >> int j, N; >> int

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Gabriel Genellina
En Sun, 28 Dec 2008 00:40:52 -0200, Daniel Fetchinson escribió: You MUST check EVERY function call for errors! Yes, I know :) Believe me, if you don't, there is a risk of crashing the program. And they're a lot harder to find and fix. And check the argument's type (how do you know i

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
I agree that array.array is more efficient than a list but the input for my function will come from PIL and PIL returns a list. So I have a list to begin with which will be passed to the C function. >>> With recent versions of PIL, numpy can create an array from an Image very >>> qui

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>> This is the function I have, the corresponding python function will >> take two equal length lists of integers and the C function will >> compute their sum and return the result as a python tuple. >> >> >> static PyObject *func( PyObject * self, PyObject * args ) >> { >> int j, N; >> int

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Robert Kern
Daniel Fetchinson wrote: I agree that array.array is more efficient than a list but the input for my function will come from PIL and PIL returns a list. So I have a list to begin with which will be passed to the C function. With recent versions of PIL, numpy can create an array from an Image ver

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Gabriel Genellina
En Sat, 27 Dec 2008 22:54:52 -0200, Daniel Fetchinson escribió: This is the function I have, the corresponding python function will take two equal length lists of integers and the C function will compute their sum and return the result as a python tuple. static PyObject *func( PyObject * se

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
On 12/27/08, Robert Kern wrote: > Daniel Fetchinson wrote: > >> I agree that array.array is more efficient than a list but the input >> for my function will come from PIL and PIL returns a list. So I have a >> list to begin with which will be passed to the C function. > > With recent versions of P

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Aaron Brady
On Dec 27, 6:06 pm, Scott David Daniels wrote: > Daniel Fetchinson wrote: > > I have a list to begin with which will be passed to the C function. > >  > I assume converting the list to an array.array and passing that to the C > > > function doesn't make any difference in terms of speed since t

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>> I agree that array.array is more efficient than a list but the input >> for my function will come from PIL and PIL returns a list. So I have a >> list to begin with which will be passed to the C function. > > With recent versions of PIL, numpy can create an array from an Image very > quickly, po

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Robert Kern
Daniel Fetchinson wrote: I agree that array.array is more efficient than a list but the input for my function will come from PIL and PIL returns a list. So I have a list to begin with which will be passed to the C function. With recent versions of PIL, numpy can create an array from an Image v

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Scott David Daniels
Daniel Fetchinson wrote: I have a list to begin with which will be passed to the C function. > I assume converting the list to an array.array and passing that to the C function doesn't make any difference in terms of speed since the operation itself will be done in the C function anyway.

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
>> I have considered using ctypes but for my needs using the C API >> directly seems more reasonable. array.array and numpy.array doesn't >> fit my needs since I need to do long and complicated operations on the >> two (pretty large) integer arrays that would be too slow using >> array.array and nu

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Scott David Daniels
Daniel Fetchinson wrote: I have considered using ctypes but for my needs using the C API directly seems more reasonable. array.array and numpy.array doesn't fit my needs since I need to do long and complicated operations on the two (pretty large) integer arrays that would be too slow using array.

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
also an N length array. From python I'd like to call this >> function as >> ret = func( [ 1, 2, 3 ], [ 2, 3, 4] ) > > This requirement pretty much dictates the slow answer you have. I'm not sure I understand what you mean. > > Does this mean that I can only pas

Re: C API: array of floats/ints from python to C and back

2008-12-27 Thread Scott David Daniels
array. From python I'd like to call this function as ret = func( [ 1, 2, 3 ], [ 2, 3, 4] ) This requirement pretty much dictates the slow answer you have. > Does this mean that I can only pass the arrays from python to C as > generic python objects and in a later operation I need to ge

C API: array of floats/ints from python to C and back

2008-12-27 Thread Daniel Fetchinson
ke to call this function as ret = func( [ 1, 2, 3 ], [ 2, 3, 4] ) I've read through the docs at http://docs.python.org/extending/extending.html and also http://docs.python.org/c-api/arg.html from which I learned how to pass a fixed number of basic datatypes (int, float, string) from python to C

Re: How to transfer data structure or class from Python to C/C++?

2008-12-21 Thread Aaron Brady
On Oct 16, 9:10 am, Hongtian wrote: snip > Not exactly. > In my C/C++ application, I have following function or flow: > void func1() > { > call PyFunc(struct Tdemo, struct &Tdemo1); > } > I mean I want to invoke Python function 'PyFunc' and transfer a data > structure 'Tdemo' to this fu

Re: How to transfer data structure or class from Python to C/C++?

2008-10-22 Thread Gabriel Genellina
En Tue, 21 Oct 2008 15:21:45 -0200, Aaron Brady <[EMAIL PROTECTED]> escribió: On Oct 21, 12:46 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: Hi Gabriel, Sorry, did you have some questions about it? No, that empty message was posted by mistake, sorry. -- Gabriel Genellina -- http://mail

Re: How to transfer data structure or class from Python to C/C++?

2008-10-21 Thread Aaron Brady
On Oct 21, 12:46 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 17 Oct 2008 20:03:44 -0300, Aaron "Castironpi" Brady   > <[EMAIL PROTECTED]> escribió: > > > > > On Oct 16, 9:10 am, Hongtian <[EMAIL PROTECTED]> wrote: > >> Not exactly. > > >> In my C/C++ application, I have following f

Re: How to transfer data structure or class from Python to C/C++?

2008-10-20 Thread Gabriel Genellina
En Fri, 17 Oct 2008 20:03:44 -0300, Aaron "Castironpi" Brady <[EMAIL PROTECTED]> escribió: On Oct 16, 9:10 am, Hongtian <[EMAIL PROTECTED]> wrote: Not exactly. In my C/C++ application, I have following function or flow: void func1() {     call PyFunc(struct Tdemo, struct &Tdemo1); } I

Re: How to transfer data structure or class from Python to C/C++?

2008-10-17 Thread Aaron "Castironpi" Brady
On Oct 16, 9:10 am, Hongtian <[EMAIL PROTECTED]> wrote: > Not exactly. > > In my C/C++ application, I have following function or flow: > > void func1() > { >     call PyFunc(struct Tdemo, struct &Tdemo1); > > } > > I mean I want to invoke Python function 'PyFunc' and transfer a data > structure

Re: How to transfer data structure or class from Python to C/C++?

2008-10-17 Thread Aaron "Castironpi" Brady
a newer of Python. I want to ask below question: > > > > I have a C/C++ application and I want to use Python as its extension. > > > To do that, I have to transfer some data structure from C/C++ > > > application to Python and get some data structure from Python to C/C++

Re: How to transfer data structure or class from Python to C/C++?

2008-10-17 Thread Aaron "Castironpi" Brady
a newer of Python. I want to ask below question: > > > > I have a C/C++ application and I want to use Python as its extension. > > > To do that, I have to transfer some data structure from C/C++ > > > application to Python and get some data structure from Python to C/C++

Re: How to transfer data structure or class from Python to C/C++?

2008-10-16 Thread Aaron "Castironpi" Brady
On Oct 16, 9:10 am, Hongtian <[EMAIL PROTECTED]> wrote: > Not exactly. > > In my C/C++ application, I have following function or flow: > > void func1() > { >     call PyFunc(struct Tdemo, struct &Tdemo1); > > } > > I mean I want to invoke Python function 'PyFunc' and transfer a data > structure

Re: How to transfer data structure or class from Python to C/C++?

2008-10-16 Thread Hongtian
te: > On Oct 15, 8:08 pm, Hongtian <[EMAIL PROTECTED]> wrote: > > > Hi friends, > > > I am a newer of Python. I want to ask below question: > > > I have a C/C++ application and I want to use Python as its extension. > > To do that, I have to transfer s

Re: How to transfer data structure or class from Python to C/C++?

2008-10-15 Thread Aaron "Castironpi" Brady
plication to Python and get some data structure from Python to C/C++ > application. I have researched Python document, but the example only > describes how to transfer some simple data, such as integer,char, > etc. > > Could you please guide me to do that? or tell me some document to

Re: How to transfer data structure or class from Python to C/C++?

2008-10-15 Thread bearophileHUGS
Hongtian: > Could you please guide me to do that? or tell me some document to have > a research? You can start googling for: - SWIG - Boost.Python - SIP - ctypes (built-in module) - And more. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

How to transfer data structure or class from Python to C/C++?

2008-10-15 Thread Hongtian
Hi friends, I am a newer of Python. I want to ask below question: I have a C/C++ application and I want to use Python as its extension. To do that, I have to transfer some data structure from C/C++ application to Python and get some data structure from Python to C/C++ application. I have

Re: Pass data from Python to C++

2008-05-15 Thread Christian Heimes
brad schrieb: > However, other components can be written in a more user friendly, more > easily maintained language. We've chosen Python for this. The main > question now is how to pass the computationally heavy info to c++ from > within Pyhton. os.system is not ideal. Just wondering how other folk

Re: Pass data from Python to C++

2008-05-15 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>, brad <[EMAIL PROTECTED]> wrote: > I have some c++ binaries that do rather intense number computations. > They do it well and rather quickly compared to other languages (not just > Python). ... > > However, other components can be written in a more user friendly,

Re: Pass data from Python to C++

2008-05-15 Thread Gary Herron
brad wrote: I have some c++ binaries that do rather intense number computations. They do it well and rather quickly compared to other languages (not just Python). An example: [EMAIL PROTECTED]:~/$ date && ./compute.cpp.o < 1_million.txt > /dev/null && date Thu May 15 13:08:28 EDT 2008 Thu Ma

Pass data from Python to C++

2008-05-15 Thread brad
I have some c++ binaries that do rather intense number computations. They do it well and rather quickly compared to other languages (not just Python). An example: [EMAIL PROTECTED]:~/$ date && ./compute.cpp.o < 1_million.txt > /dev/null && date Thu May 15 13:08:28 EDT 2008 Thu May 15 13:08:31

RE: From Python to c++

2006-03-22 Thread Ames Andreas
Hello Marco, > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > g] On Behalf Of Marco Aschwanden > Sent: Tuesday, March 21, 2006 8:43 PM > Subject: From Python to c++ > > parsed = { > "name":["Mac", "Mike

Re: From Python to c++

2006-03-22 Thread Marco Aschwanden
Heck! I received 1 useless answer in comp.lang.c++ and here I get useful links/hints and even a code-pattern! Great. Thank you all. Sorry for posting a c++-problem here, but it was derived from my thinking the Python way... Cheers, Marco -- http://mail.python.org/mailman/listinfo/python-li

Re: From Python to c++

2006-03-22 Thread Marco Aschwanden
On Wed, 22 Mar 2006 08:11:24 +0100, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > This is so scary, I probably shouldn't post this. It sounds from your > description, you really want RTTI. I haven't done this in a long > while, so I'm not sure there is an easier way. But the program below >

Re: From Python to c++

2006-03-21 Thread [EMAIL PROTECTED]
Marco Aschwanden wrote: > This is actually a c++ problem. Got no satisfying answer on comp.lang.c++. > Maybe you can help better because I know, there are many c++-converts ;). > > Suppose you've got the following list (first line has field names, second > line has types and any row after is data):

Re: From Python to c++

2006-03-21 Thread Gonzalo Monzón
Hi Marco! Perhaps the simpler way could be to store them all in the map as string data, but of course, it depends on what you must do later with that data, so you can save the field types and convert from string when needed to use any value... if you do not need to process later that data at a

Re: From Python to c++

2006-03-21 Thread Farshid Lashkari
> Any suggestions are very welcome! Are you allowed to use any boost libraries? If so then boost::any would probably help. The boost::any object can contain any object type. So you could have a single container that looked like the following: std::map< std::string, std::vector > result; Since

Re: From Python to c++

2006-03-21 Thread Roman Yakovenko
On 3/21/06, Marco Aschwanden <[EMAIL PROTECTED]> wrote: > Any suggestions are very welcome! > > > Regards, > Marco (Forced to code in c++ again let me estimate the simplicity of > python) C++ is also simple, if you have right library to do the job: http://boost.org/doc/html/variant.html http://bo

From Python to c++

2006-03-21 Thread Marco Aschwanden
This is actually a c++ problem. Got no satisfying answer on comp.lang.c++. Maybe you can help better because I know, there are many c++-converts ;). Suppose you've got the following list (first line has field names, second line has types and any row after is data): csv = "name,age,place\nstri