473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

multi-line input?

I'm writing a C++ application with an embedded Python interpreter.
Command text is captured and passed to the interpreter a single line
at a time. My question is this: is there a simple way of determining
whether a given input line of text will cause the prompt to change
from the regular ">>>" to the multi-line "..." before sending the text
to the interpreter? I suppose the completely correct solution would be
tokenize and parse the entire string and then examine all the
constituent parts, but that seems like a lot more work than I really
want to do.

As far as I can tell, there are only a few ways to trigger the multi-
line input prompt:

- if-statement, for-loop, function or class definition
- line continuation (\)
- block quote (""" or ''')

Any help would be greatly appreciated.

May 14 '07 #1
2 2940
En Mon, 14 May 2007 18:50:35 -0300, <jo*******@gmail.comescribió:
I'm writing a C++ application with an embedded Python interpreter.
Command text is captured and passed to the interpreter a single line
at a time. My question is this: is there a simple way of determining
whether a given input line of text will cause the prompt to change
from the regular ">>>" to the multi-line "..." before sending the text
to the interpreter? I suppose the completely correct solution would be
tokenize and parse the entire string and then examine all the
constituent parts, but that seems like a lot more work than I really
want to do.
There is an emulation of the read-eval-print loop written in Python
itself, see the code module. In particular, compile_command tries to
determine whether the entered text is a complete Python statement,
contains a syntax error, or requires more input.
If you want to stay with C code, you could use Py_CompileString and see if
the already entered code can be compiled or not - but I'm not sure if you
will actually be able to distinguish a SyntaxError from an incomplete
statement.
As far as I can tell, there are only a few ways to trigger the multi-
line input prompt:

- if-statement, for-loop, function or class definition
- line continuation (\)
- block quote (""" or ''')
- Any expression involving an open group of () [] {}

--
Gabriel Genellina

May 15 '07 #2
Ah, thanks. Using the information you provided, I found the following
page:

http://archives.free.net.ph/message/...a616bf.en.html

It's not perfect, but it's close enough for what I need.

May 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
5
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.