views:

48

answers:

1

Hello i am learning python(so i can use qt with python not only c++) and i'm curios if it would be possible to embed a python interpreter in my application as a repl. I would like to give users to possibility to script the app using python either loading a file (and that file to act as a plugin for the app) or by evaluating code entered in a text box or something like that. Just like you can embed the interpreter in C or C++ and script the app using python can this be done if the application is itself written in python(and made a stand-alone binary using py2exe or something similar)? something like Anders did with the C# repl or Miguel with mono.

Thanks.

A: 

Well, this is all certainly possible, but not beginner stuff :p

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.

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 it's 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.

THC4k
Would you say it is easier to build the application in c++/qt and allow scripting in python using boost.python or something similar than to build the app in python/qt and allow scripting in python?
Olorin
No, using Python is much easier. If you wrote your application in C++, you'd have to write an extra Python wrapper for it's C++ API. If you write it in Python plugins can call the API directly.
THC4k