interpreter

python: ignoring leading “>>>” and “…” in interactive mode?

不羁岁月 提交于 2019-12-04 02:44:59
Many online python examples show interactive python sessions with normal leading ">>>" and "..." characters before each line. Often, there's no way to copy this code without also getting these prefixes. In these cases, if I want to re-paste this code into my own python interpreter after copying, I have to do some work to first strip off those prefixes. Does anyone know of a way to get python or iPython (or any other python interpreter) to automatically ignore leading ">>>" and "..." characters on lines that are pasted in? Example: >>> if True: ... print("x") ... You just need to either switch

how to check errors happening inside scala interpreter programatically

半世苍凉 提交于 2019-12-03 17:34:46
I am executing scala code snippets using scala.tools.nsc.Interpreter When the code snippet is correct, everything is fine, but when it is buggy, my code is unable to find out and happily goes on. I would like to get an exception or method to call to get any error that happened during last evaluation by the interpreter. my code: import scala.tools.nsc.Interpreter import scala.tools.nsc.Settings object RuntimeEval { def main(args: Array[String]): Unit = { var msg = "fail" val eval = new RuntimeEval msg = eval.eval(msg,"\"success\"") println(msg) var anInt = 0 while(true){ println("Enter an

Python CTRL+C to exit interpreter?

懵懂的女人 提交于 2019-12-03 17:04:59
Python 2.73 Why is it on my laptop when I hit CTRL + C , I can exit the interpreter and on my desktop hitting CTRL + C will make the interpreter shoot back at me a KeyboardInterrupt message. How can I get rid of this KeyboardInterrupt and go back to exiting with CTRL + C ! On my desktop it's required to input CTRL + Z and hitting enter to exit. I am using PowerShell on both computer. Same 64bit, one is Win7 one is Win8 Stephan Wenger You could change the signal handler for CTRL - C to something that exits the interpreter: import signal import sys signal.signal(signal.SIGINT, lambda number,

Picking a front-end/interpreter for a scientific code

僤鯓⒐⒋嵵緔 提交于 2019-12-03 16:11:28
The simulation tool I have developed over the past couple of years, is written in C++ and currently has a tcl interpreted front-end. It was written such that it can be run either in an interactive shell, or by passing an input file. Either way, the input file is written in tcl (with many additional simulation-specific commands I have added). This allows for quite powerful input files (e.g.- when running monte-carlo sims, random distributions can be programmed as tcl procedures directly in the input file). Unfortunately, I am finding that the tcl interpreter is becoming somewhat limited

Interpret something, and run the generated bytecode in Java?

佐手、 提交于 2019-12-03 14:46:47
I'm writing a toy interpreter with a REPL in Java. I'd like to generate bytecode from the language and run that, instead of interpreting an AST and running that instead. Since my Java is a bit rusty, is it possible to run generated bytecode on the fly on the JVM? You can use java.lang.Classloader.defineClass(), which turns bytecode into a Class object. You can the call newInstance() on the resulting Class object, and off you go. Have a look at Javassist which contains a snippet compiler allowing you to compile Java snippets to bytecode and define them as a method in a class which you can then

Embed python interpreter in a python application

99封情书 提交于 2019-12-03 14:38:46
i'm looking for a way to ship the python interpreter with my application (also written in python), so that it doesn't need to have python installed on the machine. I searched google and found a bunch of results about how to embed the python interpreter in applications written in various languages, but nothing for applications writtent in python itself... I don't need to "hide" my code or make a binary like cx_freeze does, i just don't want my users to have to install python to use my app, that's all. Thanks. For distribution on Windows machines, look into py2exe py2exe is a Python Distutils

Restarting a Python Interpreter Quietly

谁说我不能喝 提交于 2019-12-03 13:33:35
I have a python interpreter embedded inside an application. The application takes a long time to start up and I have no ability to restart the interpreter without restarting the whole application. What I would like to do is to essentially save the state of the interpreter and return to that state easily. I started by storing the names of all modules in sys.modules that the python interpreter started with and then deleting all new modules from sys.modules when requested. This appears to make the interpreter prepared to re-import the same modules even though it has already imported them before.

LIst Comprehensions: References to the Components

こ雲淡風輕ζ 提交于 2019-12-03 12:52:01
In sum: I need to write a List Comprehension in which i refer to list that is being created by the List Comprehension. This might not be something you need to do every day, but i don't think it's unusual either. Maybe there's no answer here--still, please don't tell me i ought to use a for loop. That might be correct, but it's not helpful. The reason is the problem domain: this line of code is part of an ETL module, so performance is relevant, and so is the need to avoid creating a temporary container--hence my wish to code this step in a L/C. If a for loop would work for me here, i would just

Compiling and using Groovy classes from Java at runtime?

淺唱寂寞╮ 提交于 2019-12-03 12:06:27
问题 I have an app which I'd like to make extensible by letting users define classes in Groovy, eventually implementing some interfaces. The key aspect is that it should be interpreted/compiled at runtime. I.e. I need my app to take the .groovy and compile it. Doing it during boot is ok. Then, of course, my app should be able to instantiate that class. I see two solutions: 1) Compile while the app runs, put the classes somewhere on classpath, and then just load the classes, pretending they were

JIT code generation techniques

一曲冷凌霜 提交于 2019-12-03 11:15:07
问题 How does a virtual machine generate native machine code on the fly and execute it? Assuming you can figure out what are the native machine op-codes you want to emit, how do you go about actually running it? Is it something as hacky as mapping the mnemonic instructions to binary codes, stuffing it into an char* pointer and casting it as a function and executing? Or would you generate a temporary shared library (.dll or .so or whatever) and load it into memory using standard functions like