I have a Python application that simulates the behaviour of a system, let's say a car.
The application defines a quite large set of variables, some corresponding to real world parameters (the remaining fuel volume, the car speed, etc.) and others related to the simulator internal mechanics which are of no interest to the user.
Everything works fine, but currently the user can have no interaction with the simulation whatsoever during its execution: she just sets simulation parameters, lauchs the simulation, and waits for its termination.
I'd like the user (i.e. not the creator of the application) to be able to write Python scripts, outside of the app, that could read/write the variables associated with the real world parameters (and only these variables).
For instance, at t=23s (this condition I know how to check for), I'd like to execute user script gasLeak.py
, that reads the remaining fuel value and sets it to half its current value.
To sum up, how is it possible, from a Python main app, to execute user-written Python scripts that can access and modifiy only a pre-defined subset of the main script variables. In a perfect world, I'd also like that modifications applied to user scripts during the running of the app to be taken into account without having to restart said app (something along the reload
ing of a module).