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 relevant
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, "UT
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.
Thanks
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 = PyBytes_AS_STRING(pListStrE
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:
"""PyObjec
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:
>>
>
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 fu
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
>
// 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
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:
>
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 use
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
http://web.mit.edu/people/amliu/vrut/pyth
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 "a
This is a follow-on to a question I asked yesterday, which was answered by
MRAB. I'm using the Python C API to load the Gutenberg corpus from the nltk
library and iterate through the sentences. The Python code I am trying to
replicate is:
from nltk.corpus import gutenberg
for i, fileid in en
14 matches
Mail list logo