Re: Helloworld with Python C extension

2016-09-07 Thread Lawrence D’Oliveiro
On Tuesday, August 30, 2016 at 6:07:15 PM UTC+12, Ganesh Pal wrote: > I was just wondering how could the C extension be debugged ? My usual way of debugging C code is to stick printf statements close to where I think the problem areas might be. Write to stderr, not stdout, so you can redirec

Re: Helloworld with Python C extension

2016-08-30 Thread Christian Gollwitzer
Am 30.08.16 um 08:06 schrieb Ganesh Pal: Py_BuildValue with an "s" expects a C string - that is, a pointer to char, not just a single character. You'd need to do something like this: char buf[2] = {char1, 0}; return Py_BuildValue("s", buf); ChrisA Thanks Chris for the clue's it worked,

Re: Helloworld with Python C extension

2016-08-29 Thread Ganesh Pal
> > > > Py_BuildValue with an "s" expects a C string - that is, a pointer to > char, not just a single character. You'd need to do something like > this: > > char buf[2] = {char1, 0}; > return Py_BuildValue("s", buf); > > ChrisA Thanks Chris for the clue's it worked, I was just wondering ho

Re: Helloworld with Python C extension

2016-08-29 Thread Stefan Behnel
Ganesh Pal schrieb am 29.08.2016 um 19:30: > I need you input on the below hello world program. I a m trying to add a > python binding which will return the character for the given index . I am > on Python 2.7 and linux > > Example : > >>> string ='helloworld' > >>> dda_hello(5) > >>> 'w' >

Re: Helloworld with Python C extension

2016-08-29 Thread MRAB
On 2016-08-29 18:30, Ganesh Pal wrote: Hello Team , I need you input on the below hello world program. I a m trying to add a python binding which will return the character for the given index . I am on Python 2.7 and linux Example : string ='helloworld' dda_hello(5) 'w' /* + * Hello

Re: Helloworld with Python C extension

2016-08-29 Thread Chris Angelico
On Tue, Aug 30, 2016 at 3:30 AM, Ganesh Pal wrote: > +char dda_hello(int i) > + { > + return string[i]; > + } > + > + return Py_BuildValue("s",char1); Py_BuildValue with an "s" expects a C string - that is, a pointer to char, not just a single character. You'd need to do someth

Helloworld with Python C extension

2016-08-29 Thread Ganesh Pal
Hello Team , I need you input on the below hello world program. I a m trying to add a python binding which will return the character for the given index . I am on Python 2.7 and linux Example : >> string ='helloworld' >>dda_hello(5) >> 'w' /* + * Hello world example for python bindings +