Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Error in Extending/Embedding FAQ, point 16: How do I tell"incomplete input" from "invalid input"?

Thread Tools

Error in Extending/Embedding FAQ, point 16: How do I tell"incomplete input" from "invalid input"?

Dietrich Bollmann
Posts: n/a

Both code examples from paragraph 16 from the Python Extending /
Embedding FAQ - 'How do I tell "incomplete input" from "invalid input"?'
( ) do not work with the current state of Python anymore.

In the second code example, the error message returned by Python is
checked in order to differentiate errors caused by an incomplete input
from other syntax errors:

if (PyArg_ParseTuple (val, "sO", &msg, &obj) &&
!strcmp (msg, "unexpected EOF while parsing")) /* E_EOF */

In the current Python version there are more error messages indicating an
incomplete Python input and I could make the code work for a while
by adding the following strings to the condition:

/* error messages indicating an incomplete input */
if (PyArg_ParseTuple(error, "sO", &message, &obj) &&
(!strcmp(message, "unexpected EOF while parsing") ||
!strcmp(message, "expected an indented block") ||
!strcmp(message, "EOF while scanning triple-quoted string")
) { /* E_EOF */

but recently there are also cases which generate error messages
which are too general to be added to this list.

The following code for example:

>>> eins = [1,

... 2,
... 3]

is accepted without any problem by the Python shell.

When using the code from the FAQ and entering it line by line
already the second line causes a simple "invalid syntax" error:

>>> eins = [1,

... 2,
File "<stdin>", line 2
SyntaxError: invalid syntax

which is to general to be integrated into the list of tested
error messages as it might be caused also by code like:

>>> one two

File "<stdin>", line 1
one two
SyntaxError: invalid syntax

which generates an "invalid syntax" error even in the Python shell.

I also tried the first code example of paragraph
'16 How do I tell "incomplete input" from "invalid input"?'
of the FAQ in order to see if it could be used to make the
difference between syntax errors and incomplete code errors.
But - as in the case before - the returned error
code is E_SYNTAX (14 = Syntax error) and not E_EOF (11 = End Of File)
as should be expected.

Is there anybody who has an idea how to differentiate the
first case from the second in order to mimic the behaviour of
the Python shell from c code?

If this shouldn't be possible lists split into different lines
couldn't be accepted anymore or the feature of the Python shell
to described in paragraph 16 of the faq:

Sometimes you want to emulate the Python interactive interpreter's
behavior, where it gives you a continuation prompt when the input
is incomplete (e.g. you typed the start of an "if" statement or you
didn't close your parentheses or triple string quotes), but it gives
you a syntax error message immediately when the input is invalid.

would have to be given up and every entered line of code would have to
be terminated by an empty line before evaluation

Thanks for any help, Dietrich

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
Scenario 5: IS-IS routing on Frame Relay Multi-point and Point-to-Point David Sudjiman Cisco 0 06-08-2006 09:11 AM
point to point protocol Gopi VHDL 1 07-13-2004 02:37 PM
help, please!! cisco 827H point per point configuration javi Cisco 1 10-16-2003 07:33 AM