jep icon indicating copy to clipboard operation
jep copied to clipboard

Add a method to run script from a buffer

Open mathbagu opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe. Currently there are two ways to evaluate a script:

  • use runScript if the script is stored in a file
  • use eval to evaluate statement one by one (interactive mode)
  • read the content to a buffer (String) and use eval

Describe the solution you'd like It could be nice to have a function that evaluate a script from an InputStream. The implementation is not really easy to write, because I have to skip the empty lines properly, the commented lines... and buffer statements that have to be evaluate as once.

Describe alternatives you've considered I try to write a Java loop that call eval for each statement, but:

  • lines that begins by # has to be ignored (why not by the JEP implementation?)
  • empty lines could be either an end of statement or to continue indentation

Additional context Add any other context or screenshots about the feature request here.

mathbagu avatar Sep 21 '20 10:09 mathbagu

Jep v3.9 added the exec method to the interpreters. Exec allows executing multiple python statements without the limitations of eval, which is only intended for executing a single statement.

bsteffensmeier avatar Sep 21 '20 14:09 bsteffensmeier

@mathbagu, did exec work for you? I'm not sure how we could implement what you want in Jep without reading the entire InputStream.

ndjensen avatar Sep 14 '21 04:09 ndjensen

I am closing this as inactive. I believe the exec method solves the problems with needing to sanitize input and there are numerous utility methods in java for reading files and streams into a String that can be used by the exec method

bsteffensmeier avatar Nov 01 '22 21:11 bsteffensmeier