How to use a Python REPL in a script
I am learning Python to use QT with Python, not only C++, and am curious if I can embed a Python interpreter in my application as a REPL?
I want to allow users to script either loading a file and that file act as a plugin, or by evaluating code entered in a text box or something simil开发者_如何学Pythonar to embedding the interpreter in C or C++ and script the application using Python.
Can this be done if the application is itself written in Python and made into a standalone binary using py2exe or something similar, something like Anders did with the C# REPL or Miguel with Mono.
Well, this is all certainly possible, but it is not beginner stuff.
Python offers a read-eval loop as a module, but you'd still have so create a console in QT where you can type in input and display results.
The same goes for a plugin system. It's very easy to import a script as a plugin and the plugin just has to import your application to access its state. But that's hardly a real plugin system, you'd want to create a proper API so the plugins don't break whenever something in the app changes.
精彩评论