Re: C extension custom types in abi3 module

2022-12-08 Thread Robin Becker
On 08/12/2022 12:52, Robin Becker wrote: I am trying to split off reportlab C extensions to simplify installations and make use of more advanced packages. A simple extension is easily converted to being an abi3 module. However, another has a custom type which uses the old style mechanisms

Re: C API PyObject_CallFunctionObjArgs returns incorrect result

2022-03-07 Thread Jen Kris via Python-list
Thanks to MRAB and Chris Angelico for your help.  Here is how I implemented the string conversion, and it works correctly now for a library call that needs a list converted to a string (error handling not shown): PyObject* str_sentence = PyObject_Str(pSentence);   PyObject* separator =

Re: C API PyObject_CallFunctionObjArgs returns incorrect result

2022-03-07 Thread MRAB
On 2022-03-07 17:05, Jen Kris wrote: Thank you MRAB for your reply. Regarding your first question, pSentence is a list.  In the nltk library, nltk.word_tokenize takes a string, so we convert sentence to string before we call nltk.word_tokenize: >>> sentence = " ".join(sentence) >>> pt =

Re: C API PyObject_CallFunctionObjArgs returns incorrect result

2022-03-07 Thread Chris Angelico
On Tue, 8 Mar 2022 at 04:13, Jen Kris wrote: > > > The PyObject str_sentence is a string representation of a list. I need to > convert the list to a string like "".join because that's what the library > call takes. > What you're doing is the equivalent of str(sentence), not "".join(sentence).

Re: C API PyObject_CallFunctionObjArgs returns incorrect result

2022-03-07 Thread Jen Kris via Python-list
The PyObject str_sentence is a string representation of a list.  I need to convert the list to a string like "".join because that's what the library call takes.  Mar 7, 2022, 09:09 by ros...@gmail.com: > On Tue, 8 Mar 2022 at 04:06, Jen Kris via Python-list > wrote: > >> But with the C API

Re: C API PyObject_CallFunctionObjArgs returns incorrect result

2022-03-07 Thread Chris Angelico
On Tue, 8 Mar 2022 at 04:06, Jen Kris via Python-list wrote: > But with the C API it looks like this: > > PyObject *pSentence = PySequence_GetItem(pSents, sent_count); > PyObject* str_sentence = PyObject_Str(pSentence); // Convert to string > > PyObject* repr_str = PyObject_Repr(str_sentence);

Re: C API PyObject_CallFunctionObjArgs returns incorrect result

2022-03-07 Thread Jen Kris via Python-list
Thank you MRAB for your reply. Regarding your first question, pSentence is a list.  In the nltk library, nltk.word_tokenize takes a string, so we convert sentence to string before we call nltk.word_tokenize: >>> sentence = " ".join(sentence) >>> pt = nltk.word_tokenize(sentence) >>>

Re: C API PyObject_CallFunctionObjArgs returns incorrect result

2022-03-06 Thread MRAB
On 2022-03-07 00:32, Jen Kris via Python-list wrote: I am using the C API in Python 3.8 with the nltk library, and I have a problem with the return from a library call implemented with PyObject_CallFunctionObjArgs. This is the relevant Python code: import nltk from nltk.corpus import

Re: C is it always faster than nump?

2022-02-28 Thread Edmondo Giovannozzi
Il giorno sabato 26 febbraio 2022 alle 19:41:37 UTC+1 Dennis Lee Bieber ha scritto: > On Fri, 25 Feb 2022 21:44:14 -0800, Dan Stromberg > declaimed the following: > >Fortran, (still last I heard) did not support pointers, which gives Fortran > >compilers the chance to exploit a very nice class

Re: C is it always faster than nump?

2022-02-26 Thread Dennis Lee Bieber
On Fri, 25 Feb 2022 21:44:14 -0800, Dan Stromberg declaimed the following: >Fortran, (still last I heard) did not support pointers, which gives Fortran >compilers the chance to exploit a very nice class of optimizations you >can't use nearly as well in languages with pointers. > Haven't

Re: C is it always faster than nump?

2022-02-26 Thread Neil
Dan Stromberg wrote: > On Fri, Feb 25, 2022 at 8:12 AM BELAHCENE Abdelkader < > abdelkader.belahc...@enst.dz> wrote: > >> Hi, >> a lot of people think that C (or C++) is faster than python, yes I agree, >> but I think that's not the case with numpy, I believe numpy is faster than >> C, at least

Re: C is it always faster than nump?

2022-02-25 Thread BELAHCENE Abdelkader
Thanks every body, I want to close the subject, but just a naive question: Does numpy use a* vectorization *for arrays? I mean when I add 2 arrays ( or in sum function) how it is done, in an other word b=np.arange(100); t=np.sum(b) is equivalent or not to s=0 for i in range(100): s +=b[i]

Re: C is it always faster than nump?

2022-02-25 Thread Dan Stromberg
On Fri, Feb 25, 2022 at 8:12 AM BELAHCENE Abdelkader < abdelkader.belahc...@enst.dz> wrote: > Hi, > a lot of people think that C (or C++) is faster than python, yes I agree, > but I think that's not the case with numpy, I believe numpy is faster than > C, at least in some cases. > This is all

Re: C is it always faster than nump?

2022-02-25 Thread Dan Stromberg
On Fri, Feb 25, 2022 at 9:03 PM Chris Angelico wrote: > On Sat, 26 Feb 2022 at 15:39, Avi Gross via Python-list > wrote: > > Take interpreted languages including Python and R that specify all kinds > of functions that may be written within the language at first. Someone may > implement a

Re: C is it always faster than nump?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 15:39, Avi Gross via Python-list wrote: > Take interpreted languages including Python and R that specify all kinds of > functions that may be written within the language at first. Someone may > implement a function like sum() (just an example) that looks like the sum of

Re: C is it always faster than nump?

2022-02-25 Thread Avi Gross via Python-list
problems. -Original Message- From: Chris Angelico To: python-list@python.org Sent: Fri, Feb 25, 2022 11:16 pm Subject: Re: C is it always faster than nump? On Sat, 26 Feb 2022 at 14:35, Avi Gross via Python-list wrote: > But with numpy and more available anyway, it may not be necess

Re: C is it always faster than nump?

2022-02-25 Thread Avi Gross via Python-list
g on the same language, Python? -Original Message- From: Chris Angelico To: python-list@python.org Sent: Fri, Feb 25, 2022 2:58 pm Subject: Re: C is it always faster than nump? On Sat, 26 Feb 2022 at 06:44, Avi Gross via Python-list wrote: > > I agree with Richard. > > Some peopl

Re: C is it always faster than nump?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 14:35, Avi Gross via Python-list wrote: > But with numpy and more available anyway, it may not be necessary to reinvent > much of that. I was just wondering if it ever made sense to simply include it > in the base python, perhaps as a second executable with a name like

Re: C is it always faster than nump?

2022-02-25 Thread Avi Gross via Python-list
Dennis, What you describe may be a start but is it anything I might not have easily created myself? https://docs.python.org/3/library/array.html I can see creating my own object and adding those methods and attributes while gaining very little, except perhaps storage. Can I add or multiply

Re: C is it always faster than nump?

2022-02-25 Thread Oscar Benjamin
On Sat, 26 Feb 2022 at 03:10, Dennis Lee Bieber wrote: > > On Fri, 25 Feb 2022 23:06:57 + (UTC), Avi Gross > declaimed the following: > > >I do have to wonder if anyone ever considered adding back enough > >functionality into base Python to make some additions less needed. Is there > >any

Re: C is it always faster than nump?

2022-02-25 Thread Dennis Lee Bieber
On Fri, 25 Feb 2022 23:06:57 + (UTC), Avi Gross declaimed the following: >I do have to wonder if anyone ever considered adding back enough functionality >into base Python to make some additions less needed. Is there any reason the >kind of structures used by so many languages cannot be

Re: C is it always faster than nump?

2022-02-25 Thread Oscar Benjamin
On Fri, 25 Feb 2022 at 23:13, Barry wrote: > > > On 25 Feb 2022, at 23:00, Richard Damon wrote: > > > > On 2/25/22 2:47 PM, Chris Angelico wrote: > >>> On Sat, 26 Feb 2022 at 05:49, Richard Damon > >>> wrote: > >>> On 2/25/22 4:12 AM, BELAHCENE Abdelkader wrote: > Hi, > a lot of

Re: C is it always faster than nump?

2022-02-25 Thread Barry
> On 25 Feb 2022, at 23:00, Richard Damon wrote: > > On 2/25/22 2:47 PM, Chris Angelico wrote: >>> On Sat, 26 Feb 2022 at 05:49, Richard Damon >>> wrote: >>> On 2/25/22 4:12 AM, BELAHCENE Abdelkader wrote: Hi, a lot of people think that C (or C++) is faster than python, yes I

Re: C is it always faster than nump?

2022-02-25 Thread Avi Gross via Python-list
22 4:12 pm Subject: Re: C is it always faster than nump? On 2022-02-25, Richard Damon wrote: > On 2/25/22 4:12 AM, BELAHCENE Abdelkader wrote: >> Hi, >> a lot of people think that C (or C++) is faster than python, yes I agree, >> but I think that's not the case with numpy,

Re: C is it always faster than nump?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 09:58, Richard Damon wrote: > > On 2/25/22 2:47 PM, Chris Angelico wrote: > > On Sat, 26 Feb 2022 at 05:49, Richard Damon > > wrote: > >> On 2/25/22 4:12 AM, BELAHCENE Abdelkader wrote: > >>> Hi, > >>> a lot of people think that C (or C++) is faster than python, yes I

Re: C is it always faster than nump?

2022-02-25 Thread Richard Damon
On 2/25/22 2:47 PM, Chris Angelico wrote: On Sat, 26 Feb 2022 at 05:49, Richard Damon wrote: On 2/25/22 4:12 AM, BELAHCENE Abdelkader wrote: Hi, a lot of people think that C (or C++) is faster than python, yes I agree, but I think that's not the case with numpy, I believe numpy is faster than

Re: C is it always faster than nump?

2022-02-25 Thread Grant Edwards
On 2022-02-25, Richard Damon wrote: > On 2/25/22 4:12 AM, BELAHCENE Abdelkader wrote: >> Hi, >> a lot of people think that C (or C++) is faster than python, yes I agree, >> but I think that's not the case with numpy, I believe numpy is faster than >> C, at least in some cases. > > My

Re: C is it always faster than nump?

2022-02-25 Thread Chris Angelico
hings in Python change. > > The reality is that many paradigms carried too far end up falling short. > > > -Original Message- > From: Richard Damon > To: python-list@python.org > Sent: Fri, Feb 25, 2022 1:48 pm > Subject: Re: C is it always faster than nump? &

Re: C is it always faster than nump?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 05:49, Richard Damon wrote: > > On 2/25/22 4:12 AM, BELAHCENE Abdelkader wrote: > > Hi, > > a lot of people think that C (or C++) is faster than python, yes I agree, > > but I think that's not the case with numpy, I believe numpy is faster than > > C, at least in some

Re: C is it always faster than nump?

2022-02-25 Thread Avi Gross via Python-list
al Message- From: Richard Damon To: python-list@python.org Sent: Fri, Feb 25, 2022 1:48 pm Subject: Re: C is it always faster than nump? On 2/25/22 4:12 AM, BELAHCENE Abdelkader wrote: > Hi, > a lot of people think that C (or C++) is faster than python, yes I agree, > but I think

Re: C is it always faster than nump?

2022-02-25 Thread Chris Angelico
On Sat, 26 Feb 2022 at 03:13, BELAHCENE Abdelkader wrote: > *This is the Python3 program :import timeit as itimport numpy as npimport > systry : n=eval(sys.argv[1])except: print ("needs integer as argument") ; > exit() a=range(1,n+1)b=np.array(a)def func1(): return sum(a)def > func2(): return

Re: C is it always faster than nump?

2022-02-25 Thread Richard Damon
On 2/25/22 4:12 AM, BELAHCENE Abdelkader wrote: Hi, a lot of people think that C (or C++) is faster than python, yes I agree, but I think that's not the case with numpy, I believe numpy is faster than C, at least in some cases. My understanding is that numpy is written in C, so for it to be

Re: C API - How to return a Dictionary as a Dictionary type

2022-02-14 Thread Jen Kris via Python-list
Yes, that works.  This is my first day with C API dictionaries.  Now that you've explained it, it makes perfect sense.  Thanks much.  Jen Feb 14, 2022, 17:24 by ros...@gmail.com: > On Tue, 15 Feb 2022 at 12:07, Jen Kris via Python-list > wrote: > >> >> I created a dictionary with the Python

Re: C API - How to return a Dictionary as a Dictionary type

2022-02-14 Thread Chris Angelico
On Tue, 15 Feb 2022 at 12:07, Jen Kris via Python-list wrote: > > I created a dictionary with the Python C API and assigned two keys and values: > > PyObject* this_dict = PyDict_New(); > const char *key = "key1"; > char *val = "data_01"; > PyObject* val_p = PyUnicode_FromString(val); > int r =

Re: C API PyObject_Call segfaults with string

2022-02-10 Thread Jen Kris via Python-list
Thank you for that suggestion.  It allowed me to replace six lines of code with one.  :) Feb 10, 2022, 12:43 by pyt...@mrabarnett.plus.com: > On 2022-02-10 20:00, Jen Kris via Python-list wrote: > >> With the help of PyErr_Print() I have it solved.  Here is the final code >> (the part

Re: C API PyObject_Call segfaults with string

2022-02-10 Thread MRAB
On 2022-02-10 20:00, Jen Kris via Python-list wrote: With the help of PyErr_Print() I have it solved.  Here is the final code (the part relevant to sents):    Py_ssize_t listIndex = 0;    pListItem = PyList_GetItem(pFileIds, listIndex);    pListStrE = PyUnicode_AsEncodedString(pListItem,

Re: C API PyObject_Call segfaults with string

2022-02-10 Thread Jen Kris via Python-list
Hi and thanks very much for your comments on reference counting.  Since I'm new to the C_API that will help a lot.  I know that reference counting is one of the difficult issues with the C API.  I just posted a reply to Inada Naoki showing how I solved the problem I posted yesterday. 

Re: C API PyObject_Call segfaults with string

2022-02-10 Thread Jen Kris via Python-list
With the help of PyErr_Print() I have it solved.  Here is the final code (the part relevant to sents):    Py_ssize_t listIndex = 0;    pListItem = PyList_GetItem(pFileIds, listIndex);    pListStrE = PyUnicode_AsEncodedString(pListItem, "UTF-8", "strict");    pListStr =

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread MRAB
On 2022-02-10 01:37, Jen Kris via Python-list wrote: I'm using Python 3.8 so I tried your second choice: pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem); but pSents is 0x0.  pSentMod and pListItem are valid pointers. 'PyObject_CallFunction' looks like a good one to use:

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Jen Kris via Python-list
I'll do that and post back tomorrow.  The office is closing and I have to leave now (I'm in Seattle).  Thanks again for your help.  Feb 9, 2022, 17:40 by songofaca...@gmail.com: > On Thu, Feb 10, 2022 at 10:37 AM Jen Kris wrote: > >> >> I'm using Python 3.8 so I tried your second choice: >>

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Inada Naoki
On Thu, Feb 10, 2022 at 10:37 AM Jen Kris wrote: > > I'm using Python 3.8 so I tried your second choice: > > pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem); > > but pSents is 0x0. pSentMod and pListItem are valid pointers. > It means exception happened. If you are writing Python/C

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Jen Kris via Python-list
I'm using Python 3.8 so I tried your second choice: pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem); but pSents is 0x0.  pSentMod and pListItem are valid pointers.  Feb 9, 2022, 17:23 by songofaca...@gmail.com: > // https://docs.python.org/3/c-api/call.html#c.PyObject_CallNoArgs >

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Inada Naoki
// https://docs.python.org/3/c-api/call.html#c.PyObject_CallNoArgs // This function is only for one arg. Python >= 3.9 is required. pSents = PyObject_CallOneArg(pSentMod, pListItem); Or // https://docs.python.org/3/c-api/call.html#c.PyObject_CallFunctionObjArgs // This function can call function

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Jen Kris via Python-list
Right you are.  In that case should I use Py_BuildValue and convert to tuple (because it won't return a tuple for a one-arg), or should I just convert pListStr to tuple?  Thanks for your help.  Feb 9, 2022, 17:08 by songofaca...@gmail.com: > On Thu, Feb 10, 2022 at 10:05 AM Jen Kris wrote:

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Inada Naoki
On Thu, Feb 10, 2022 at 10:05 AM Jen Kris wrote: > > Thanks for your reply. > > I eliminated the DECREF and now it doesn't segfault but it returns 0x0. Same > when I substitute pListStrE for pListStr. pListStr contains the string > representation of the fileid, so it seemed like the one to

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Jen Kris via Python-list
Thanks for your reply.  I eliminated the DECREF and now it doesn't segfault but it returns 0x0.  Same when I substitute pListStrE for pListStr.  pListStr contains the string representation of the fileid, so it seemed like the one to use.  According to 

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Inada Naoki
On Thu, Feb 10, 2022 at 9:42 AM Jen Kris via Python-list wrote: > > I have everything finished down to the last line (sentences = > gutenberg.sents(fileid)) where I use PyObject_Call to call gutenberg.sents, > but it segfaults. The fileid is a string -- the first fileid in this corpus > is

Re: c extension finding the module in object initialization

2021-09-27 Thread Robin Becker
Hi Marc, Thanks for the suggestion, On 27/09/2021 09:38, Marc-Andre Lemburg wrote: Hi Robin, seeing that no one replied to your question, I'd suggest to ask this on the Python C-API ML: https://mail.python.org/mailman3/lists/capi-sig.python.org/ That's where the experts are, including the

Re: c extension finding the module in object initialization

2021-09-27 Thread Marc-Andre Lemburg
Hi Robin, seeing that no one replied to your question, I'd suggest to ask this on the Python C-API ML: https://mail.python.org/mailman3/lists/capi-sig.python.org/ That's where the experts are, including the ones who implemented the mutli-phase logic. Cheers, -- Marc-Andre Lemburg eGenix.com

Re: c-types Structure and equality with bytes/bytearray

2021-04-29 Thread Eryk Sun
On 4/26/21, Michael Hull wrote: > > my understanding was that `bytes` and `bytearray` would normally > be expected to work quite interchangeably with each other? bytearray.__eq__() is more flexible: >>> i = Int16(first=65, second=66) >>> bytearray(i).__eq__(i) True >>>

Re: c bindings with non-python thread callback while python exits

2021-01-26 Thread Barry Scott
> On 26 Jan 2021, at 14:35, Paul Grinberg wrote: > > I have a C++ library (luckily with source code, so I know what's going on) to > which I wrote c bindings. The library internally starts an event pthread > which generates callbacks back into python. The c binding for processing > these

Re: C API PyObject_GetAttrString returns not the object I expected

2019-02-10 Thread Barry Scott
On Sunday, 10 February 2019 13:58:57 GMT Stefan Behnel wrote: > Barry Scott schrieb am 10.02.19 um 13:08: > > After calling PyObject_GetAttrString() I expected to get a PyObject string > > back but I found that I had been given a instead. > > > > (gdb) p *args_o > > $4 = > > > > What is going

Re: C API PyObject_GetAttrString returns not the object I expected

2019-02-10 Thread Stefan Behnel
Barry Scott schrieb am 10.02.19 um 13:08: > After calling PyObject_GetAttrString() I expected to get a PyObject string > back but I found that I had been given a instead. > > (gdb) p *args_o > $4 = > > What is going on and how do I get from the to the object > I > want? Phil is right

Re: C API PyObject_GetAttrString returns not the object I expected

2019-02-10 Thread Phil Thompson
On 10 Feb 2019, at 12:08 pm, Barry Scott wrote: > > After calling PyObject_GetAttrString() I expected to get a PyObject string > back but I found that I had been given a instead. > > (gdb) p *args_o > $4 = > > What is going on and how do I get from the to the object > I > want? The

Re: c code generator from python

2018-02-19 Thread Stefan Behnel
bhattacharya.kush...@gmail.com schrieb am 17.01.2018 um 12:03: > Is there any python framework or any tool as which can generate C code from > python code as it is . http://cython.org/ Stefan -- https://mail.python.org/mailman/listinfo/python-list

Re: C-Python and Endianness

2017-03-27 Thread Antoon Pardon
Op 26-03-17 om 08:47 schreef Ganesh Pal: > Hello Team , > > > > > I want to write the hexadecimal string that is passed from python as it > is on disk in C , my problem is that the values are getting stored in > little endian and Are you sure you are passing a string? Or are you passing a

Re: C Python extension to export an Function

2016-09-08 Thread Lawrence D’Oliveiro
On Friday, September 2, 2016 at 3:59:21 AM UTC+12, Stefan Behnel wrote: > Manually written C-API code is simply too difficult to maintain, and also > too difficult to get right in the first place. There are just too many ways > to introduce reference leaks, crashes and long standing unnoticed bugs

Re: C Python extension to export an Function

2016-09-02 Thread dieter
Ganesh Pal writes: > ... > Thanks stefan and Gollwitzer , good to know there are many ways to do this > i.e via cython or SWIG but the C/Python API > is probably the most widely used method > - not for it’s simplicity but for the fact

Re: C Python extension to export an Function

2016-09-01 Thread Christian Gollwitzer
Hi Ganesh, Am 01.09.16 um 17:24 schrieb Ganesh Pal: Thanks stefan and Gollwitzer , good to know there are many ways to do this i.e via cython or SWIG but the C/Python API is probably the most widely used method - not for it’s simplicity but for the fact

Re: C Python extension to export an Function

2016-09-01 Thread Pavel S
If you're familiar with C++, I recommend to have a look at Boost::Python. Sample program: #include #include void world() { std::cout << "hello world" << std::endl; } BOOST_PYTHON_MODULE( hello ) { using namespace ::boost::python; def( "world", ); } Usage: python -c "import

Re: C Python extension to export an Function

2016-09-01 Thread Stefan Behnel
Ganesh Pal schrieb am 01.09.2016 um 17:24: > Thanks stefan and Gollwitzer , good to know there are many ways to do this > i.e via cython or SWIG but the C/Python API > is probably the most widely used method It certainly was, years ago, but I honestly doubt

Re: C Python extension to export an Function

2016-09-01 Thread Ganesh Pal
Thanks stefan and Gollwitzer , good to know there are many ways to do this i.e via cython or SWIG but the C/Python API is probably the most widely used method - not for it’s simplicity but for the fact that you can manipulate python objects in your C code.

Re: C Python extension to export an Function

2016-09-01 Thread Christian Gollwitzer
Am 01.09.16 um 14:30 schrieb Ganesh Pal: On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote: Ganesh Pal writes: Iam pretty new to C Python extension , I was able to export few simple modules to python and it look like the cool thing to do ... Maybe,

Re: C Python extension to export an Function

2016-09-01 Thread Stefan Behnel
Ganesh Pal schrieb am 01.09.2016 um 14:30: > On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote: >> Ganesh Pal writes: >>> Iam pretty new to C Python extension , I was able to export few simple >>> modules to python and it look like the cool thing to do ... >> >> Maybe, it is a good idea to have a look

Re: C Python extension to export an Function

2016-09-01 Thread Ganesh Pal
On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote: > Ganesh Pal writes: > > > Iam pretty new to C Python extension , I was able to export few simple > > modules to python and it look like the cool thing to do ... > > Maybe, it is a good idea to have a look

Re: C Python extension to export an Function

2016-09-01 Thread dieter
Ganesh Pal writes: > Iam pretty new to C Python extension , I was able to export few simple > modules to python and it look like the cool thing to do ... Maybe, it is a good idea to have a look at "cython". "cython" is a compiler. It translates Python code enhanced with

Re: C-API proper initialization and deallocation of subclasses

2014-06-13 Thread ptb
While there doesn't appear to be too much interest in this question I thought I would post the solution. I had to modify shoddy by adding the proper flags and clear/traverse methods such to ensure that cyclic garbage collection was properly handled. I'm not quite sure why I had to do this

Re: C++ to python for LED Matrix

2014-02-01 Thread Michael Torrie
Yes you could use Python for this sort of thing. The link you posted is just using a kernel spi driver that Python can write to just as well as C++ can (via it's /dev/spidev0.0 file). There is a python library that can talk to SPI in Python on the pi:

Re: C langauge recvmmsg() function in Python

2013-12-18 Thread Roy Smith
In article 11b3f519-e0d6-40c3-a73d-aa673b225...@googlegroups.com, justhots...@gmail.com wrote: Hi All, Is there a C langauge recvmmsg() function (receive multiple messages on a socket) equivalent in python? recvmmsg details url: http://man7.org/linux/man-pages/man2/recvmmsg.2.html AFAIK,

Re: c# async, await

2013-08-22 Thread Michael Torrie
On 08/22/2013 05:29 AM, Neal Becker wrote: So my son is now spending his days on c# and .net. He's enthusiastic about async and await, and said to me last evening, I don't think python has anything like that. I'm not terribly knowledgeable myself regarding async programming (since I

Re: c# async, await

2013-08-22 Thread Neil Cerutti
On 2013-08-22, Neal Becker ndbeck...@gmail.com wrote: So my son is now spending his days on c# and .net. He's enthusiastic about async and await, and said to me last evening, I don't think python has anything like that. I'm not terribly knowledgeable myself regarding async programming

Re: c# async, await

2013-08-22 Thread Terry Reedy
On 8/22/2013 9:57 AM, Michael Torrie wrote: On 08/22/2013 05:29 AM, Neal Becker wrote: So my son is now spending his days on c# and .net. He's enthusiastic about async and await, and said to me last evening, I don't think python has anything like that. I'm not terribly knowledgeable myself

Re: c# async, await

2013-08-22 Thread Ian Kelly
On Thu, Aug 22, 2013 at 5:29 AM, Neal Becker ndbeck...@gmail.com wrote: So my son is now spending his days on c# and .net. He's enthusiastic about async and await, and said to me last evening, I don't think python has anything like that. I'm not terribly knowledgeable myself regarding async

Re: C Python: Running Python code within function scope

2012-09-04 Thread Terry Reedy
On 9/4/2012 4:28 PM, channel727...@gmail.com wrote: The Python C API function PyEval_EvalCode let's you execute compiled Python code. I want to execute a block of Python code as if it were executing within the scope of a function, so that it has its own dictionary of local variables which don't

Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-11 Thread Giacomo Alzetta
Il giorno venerdì 10 agosto 2012 20:50:08 UTC+2, Stefan Behnel ha scritto: Giacomo Alzetta, 10.08.2012 10:20: I'm trying to implement a c-extension which defines a new class(ModPolynomial on the python side, ModPoly on the C-side). At the moment I'm writing the in-place addition, but I

Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-11 Thread Stefan Behnel
Giacomo Alzetta, 11.08.2012 08:21: I'd prefer to stick to Python and C, without having to put cython sources or cython-generated c modules (which I know are almost completely unreadable from a human point of view. Or at least the ones I saw). And the cool thing is: you don't have to read

Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-11 Thread Giacomo Alzetta
Il giorno sabato 11 agosto 2012 08:40:18 UTC+2, Stefan Behnel ha scritto: Giacomo Alzetta, 11.08.2012 08:21: I'd prefer to stick to Python and C, without having to put cython sources or cython-generated c modules (which I know are almost completely unreadable from a human point of

Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-11 Thread Stefan Behnel
Giacomo Alzetta, 11.08.2012 10:55: Il giorno sabato 11 agosto 2012 08:40:18 UTC+2, Stefan Behnel ha scritto: Giacomo Alzetta, 11.08.2012 08:21: I'd prefer to stick to Python and C, without having to put cython sources or cython-generated c modules (which I know are almost completely

Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Hans Mulder
On 10/08/12 10:20:00, Giacomo Alzetta wrote: I'm trying to implement a c-extension which defines a new class(ModPolynomial on the python side, ModPoly on the C-side). At the moment I'm writing the in-place addition, but I get a *really* strange behaviour. Here's the code for the in-place

Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Giacomo Alzetta
Il giorno venerdì 10 agosto 2012 11:22:13 UTC+2, Hans Mulder ha scritto: On 10/08/12 10:20:00, Giacomo Alzetta wrote: I'm trying to implement a c-extension which defines a new class(ModPolynomial on the python side, ModPoly on the C-side). At the moment I'm writing the in-place

Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Hans Mulder
On 10/08/12 11:25:36, Giacomo Alzetta wrote: Il giorno venerdì 10 agosto 2012 11:22:13 UTC+2, Hans Mulder ha scritto: [...] Yes, you're right. I didn't thought the combined operator would do a Py_DECREF if the iadd operation was implemented, but it obviosuly makes sense. The += operator cannot

Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Giacomo Alzetta
Il giorno venerdì 10 agosto 2012 14:21:50 UTC+2, Hans Mulder ha scritto: On 10/08/12 11:25:36, Giacomo Alzetta wrote: Il giorno venerdì 10 agosto 2012 11:22:13 UTC+2, Hans Mulder ha scritto: [...] Yes, you're right. I didn't thought the combined operator would do a Py_DECREF if

Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Stefan Behnel
Giacomo Alzetta, 10.08.2012 10:20: I'm trying to implement a c-extension which defines a new class(ModPolynomial on the python side, ModPoly on the C-side). At the moment I'm writing the in-place addition, but I get a *really* strange behaviour. You should take a look at Cython. It makes

Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread Tim Golden
On 02/08/2012 09:57, rahul wrote: I am implementing a C extension module, during this I saw that when I set the global error indicator and error message through PyErr_SetString() API and return false. But it doesn't throw any error when I tried to check the error through sys.exc_info() then

Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread rahul
Hi TJG, The above link also doesn't strictly said that return value should be NULL only, it only said that usually NULL pointer used. No where I saw that it is nessasory t At http://docs.python.org/c-api/exceptions.html. it is written that Most functions also return an error indicator,

Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread Tim Golden
On 02/08/2012 10:21, rahul wrote: Hi TJG, The above link also doesn't strictly said that return value should be NULL only, it only said that usually NULL pointer used. No where I saw that it is nessasory t At http://docs.python.org/c-api/exceptions.html. it is written that Most

Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread rahul
When I use same code base for Python 3.x, then behavior is different. In this when I return false then also it throws exception but only when any other statement get executed after this like below code: ... ... b = None try: a = testModule.check(None) except: b =

Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread Tim Golden
On 02/08/2012 10:50, rahul wrote: When I use same code base for Python 3.x, then behavior is different. In this when I return false then also it throws exception but only when any other statement get executed after this like below code: ... ... b = None try: a =

Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread Stefan Behnel
rahul, 02.08.2012 11:50: When I use same code base for Python 3.x, then behavior is different. You might want to take a look at Cython. It moves most of these funny little details off your shoulders. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: c-based version of pyPdf?

2012-05-03 Thread Kushal Kumaran
On Thu, May 3, 2012 at 8:23 PM, Chris Curvey ccur...@gmail.com wrote: I'm a long-time user of the pyPdf library, but now I'm having to work with bigger volumes -- larger PDFs and thousands of them at a shot.  So performance is starting to become a problem. Does anyone know of an analogue to

Re: C++ and Embedded Python

2012-01-20 Thread Stefan Behnel
jasonked...@hotmail.com, 20.01.2012 14:52: Is there a method to allow a pointer to an object in local memory to be shared with embedded Python within a C++ executable? The reason I require this is I have a C++ instance of a class that has data memers that are themeselves pointers to other

Re: C-API: Pass a tuple to a method of a class

2012-01-10 Thread Stefan Behnel
Hi! paspa...@noos.fr, 10.01.2012 11:57: I am trying to pass a tuple to a method of a class from C++ to Python. I get a Run Failed from the execution. thanks for help/suggestions My *suggestion* is to use Cython instead of writing the glue code yourself. There are several bugs and lots of

Re: C-API: Pass a tuple to a method of a class

2012-01-10 Thread Stefan Behnel
Hi again, just as a little teaser, to make it clear that I'm not joking, here's your code below translated into Cython. Stefan Behnel, 10.01.2012 13:33: paspa...@noos.fr, 10.01.2012 11:57: the code is the following: [...] // Class pclass = PyObject_GetAttrString(mymod, cVector); if (pclass

Re: C-API: Pass a tuple to a method of a class

2012-01-10 Thread 刘振海
Hi, I have been using Cython for a period of time. But I can not find a description for the api key word in Cython documents cdef api float compute_norm(float init_value, float x, float y, float z): Can you explain it a little bit? Thanks! Regards, Liu Zhenhai 2012/1/10 Stefan Behnel

Re: C-API: Pass a tuple to a method of a class

2012-01-10 Thread Stefan Behnel
[cleaned up top-posted citation order to make the replies readable] 刘振海, 10.01.2012 14:24: 2012/1/10 Stefan Behnel # in module gluecode.pyx (or whatever you want to name it) import mModule8 cdef api float compute_norm(float init_value, float x, float y, float z): vec =

Re: C-API: Pass a tuple to a method of a class

2012-01-10 Thread pasparis
Hi StephenThanks for examining and advise a solution. Before testing CPython I wanted to run this very simple think to send a tuple to a method of a python class.I have succeeded in sending a tuple (declared exactly the same way as I do in the code) to a method written in a python filebut as

Re: C API: Making a context manager

2011-11-01 Thread Stefan Behnel
Chris Kaynor, 31.10.2011 19:34: I am currently rewritting a class using the Python C API to improve performance of it, however I have not been able to find any documentation about how to make a context manager using the C API. You should take a look at Cython. It makes these things *so* much

Re: C API: Making a context manager

2011-11-01 Thread Chris Kaynor
On Tue, Nov 1, 2011 at 8:57 AM, Stefan Behnel stefan...@behnel.de wrote: Chris Kaynor, 31.10.2011 19:34: I am currently rewritting a class using the Python C API to improve performance of it, however I have not been able to find any documentation about how to make a context manager using the

Re: C API: Making a context manager

2011-11-01 Thread Stefan Behnel
Chris Kaynor, 01.11.2011 17:19: On Tue, Nov 1, 2011 at 8:57 AM, Stefan Behnel wrote: Chris Kaynor, 31.10.2011 19:34: I am currently rewritting a class using the Python C API to improve performance of it, however I have not been able to find any documentation about how to make a context manager

Re: C API: Making a context manager

2011-10-31 Thread Brian Curtin
On Mon, Oct 31, 2011 at 13:34, Chris Kaynor ckay...@zindagigames.com wrote: I am currently rewritting a class using the Python C API to improve performance of it, however I have not been able to find any documentation about how to make a context manager using the C API. The code I am working

  1   2   3   4   5   6   7   8   9   >