I\'d like to include Python scripting in one of my applications, that is written in Python itself.
My application must be able to call extern
"My application must be able to call external Python functions (written by the user) as callbacks".
There's an alternative that's often simpler.
Define classes which call method functions at specific points. You provide a default implementation.
Your user can then extended the classes and provide appropriate method functions instead of callbacks.
This rarely requires global variables. It's also simpler to implement because your user does something like the following
import core_classes
class MyExtension( core_classes.SomeClass ):
def event_1( self, args ):
# override the default behavior for event_1.
core_classes.main( MyExtension )
This works very smoothly, and allows maximum flexibility. Errors will always be in their code, since their code is the "main" module.