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
moerchendiser2k3, 20.03.2010 03:01:
Yes, the user is able to set a file which contains a function that
does what the user wants.
> But in a case, I expect a special return value of this function.
Ah, ok, that was the important piece of information that you omitted from
your previous posts. So
Yes, the user is able to set a file which contains a function that
does what the user wants.
But in a case, I expect a special return value of this function.
So, I need to tell him, in which file/line the error occured,
otherwise he dont know
where to look.
Imagine he set 20 files, and all of the
moerchendiser2k3, 19.03.2010 14:12:
In my case I call a funcion and I would like to get the line
where the function returned.
for instance:
def my_function():
return 3
So I would like to get line 2(in C) somehow.
Ok, so you're looking for the C-level trace function in CPython, I guess.
In my case I call a funcion and I would like to get the line
where the function returned.
for instance:
def my_function():
return 3
So I would like to get line 2(in C) somehow.
--
http://mail.python.org/mailman/listinfo/python-list
moerchendiser2k3, 18.03.2010 14:58:
Funny that you (being the OP) ask *me* what kind of line information *you*
want.
Stefan
Well, I need the line/file information of Python :
Then please explain what kind of Python line number you expect to find in C
code.
Hint: providing details often re
> Funny that you (being the OP) ask *me* what kind of line information *you*
> want.
>
> Stefan
Well, I need the line/file information of Python :
--
http://mail.python.org/mailman/listinfo/python-list
moerchendiser2k3, 17.03.2010 23:35:
1) put the line number information into the message string when you raise
the exception
you mean the line and file information of the C code, right?
Funny that you (being the OP) ask *me* what kind of line information *you*
want.
Stefan
--
http://mail.p
> 1) put the line number information into the message string when you raise
> the exception
you mean the line and file information of the C code, right?
--
http://mail.python.org/mailman/listinfo/python-list
moerchendiser2k3, 16.03.2010 19:25:
Hi, currently I am not at home, I will post some stuff when I am back.
Just the note: I throw an exception with the C API.
Looks like that
PyObject *result = PyObject_Call(my_isntance, "", NULL);
if(result==NULL)
{
PyErr_Print(); //when this happens, th
At first thanks for your answers!!!
On 16 Mrz., 21:16, Carl Banks wrote:
> Here you raise an exception with a C statement,
> and catch and print it in the very next line. The exception doesn't
> exit from Python code so there are no lines to print.
Exactly, I dont expect any line/file informati
On Mar 16, 11:25 am, moerchendiser2k3 wrote:
> Hi, currently I am not at home, I will post some stuff when I am back.
> Just the note: I throw an exception with the C API.
>
> Looks like that
>
> PyObject *result = PyObject_Call(my_isntance, "", NULL);
> if(result==NULL)
> {
> PyErr_Print(); /
Hi, currently I am not at home, I will post some stuff when I am back.
Just the note: I throw an exception with the C API.
Looks like that
PyObject *result = PyObject_Call(my_isntance, "", NULL);
if(result==NULL)
{
PyErr_Print(); //when this happens, the traceback is correct with
information
moerchendiser2k3 wrote:
> In one case I have to check the return value of PyObject_Call, and if
> its not of the correct return value,
> I throw an exception, but I just get a simple output:
>
> TypeError: Expected an instance of XYZ, no int.
>
> instead of
>
> Traceback (most called...)
> TypeE
In one case I have to check the return value of PyObject_Call, and if
its not of the correct return value,
I throw an exception, but I just get a simple output:
TypeError: Expected an instance of XYZ, no int.
instead of
Traceback (most called...)
TypeError: in line 3, file test.py: expected an i
moerchendiser2k3, 16.03.2010 12:52:
i have a serious problem and I am looking for a solution. I pass an
instance of a class from a file to PyObject_Call. When something
fails, I get a full traceback. If it succeeds, I get the return value.
Is it possible to get information from which line/file t
moerchendiser2k3, 16.03.2010 17:08:
But the stack is empty after PyObject_Call, isnt it?
I think Steve was expecting that you wanted to debug into your program,
step into the call, and find the line yourself.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
But the stack is empty after PyObject_Call, isnt it?
--
http://mail.python.org/mailman/listinfo/python-list
moerchendiser2k3 wrote:
> Hi,
>
> i have a serious problem and I am looking for a solution. I pass an
> instance of a class from a file to PyObject_Call. When something
> fails, I get a full traceback. If it succeeds, I get the return value.
>
> Is it possible to get information from which line/f
Hi,
i have a serious problem and I am looking for a solution. I pass an
instance of a class from a file to PyObject_Call. When something
fails, I get a full traceback. If it succeeds, I get the return value.
Is it possible to get information from which line/file the return
value of PyObject_Call
33 matches
Mail list logo