Python Forum
CPython: Knowing when the interpreter expects more input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CPython: Knowing when the interpreter expects more input
#1
I have embedded Python (currently 2.7.16).

After using Py_CompileString() to build user-entered Python code and then checking for errors, I use PyEval_EvalCode() to execute the resulting PyObject *.

My question: Is there a way to know from the interpreter after calling PyEval_EvalCode() that it is expecting more input? I've looked through the API, and I don't seen anything immediately apparent.

I'm currently coding that for myself, the heuristics being the interpreter needs more input if the line ends with a colon, or the current input has unbalanced parentheses ("("), brackets ("["), braces ("{") or strings.

Thanks in advance for any insights. Smile
Reply
#2
It seems to me that PyCompile_String() should fail if there are unbalanced parentheses. Have you tried this?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  partial functions before knowing the values mikisDeWitte 4 536 Dec-24-2023, 10:00 AM
Last Post: perfringo
  [CPython] Can't run script python VietVH 2 1,166 May-21-2022, 04:49 PM
Last Post: VietVH
  ImportError: /home/ali/Documents/test/charm/core/crypto/AES.cpython-39-x86_64-linux-g Anldra12 0 1,210 Apr-28-2022, 07:13 AM
Last Post: Anldra12
  Reducing runtime memory usage in Cpython interpreter david_the_graower 2 2,175 Oct-18-2021, 09:56 PM
Last Post: david_the_graower
  Navigating cpython source using python quazirfan 3 1,985 Aug-09-2021, 07:52 PM
Last Post: quazirfan
  IronPython from CPython amasis 3 2,157 Feb-05-2021, 12:26 PM
Last Post: jefsummers
  ImportError: /home/pybind11_example.cpython-37m-x86_64-linux-gnu.so: undefined symbol chaitra 2 5,029 Feb-03-2021, 05:14 AM
Last Post: chaitra
  find file not knowing the extension Leon79 6 3,016 Jul-07-2020, 04:44 PM
Last Post: Leon79
  Knowing the index of a data frame Ivannovix 1 1,838 May-01-2020, 02:51 PM
Last Post: klllmmm
  compiled cpython output wrong version bigrockcrasher 0 1,481 Feb-25-2020, 06:31 PM
Last Post: bigrockcrasher

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020