Advertisement

advanced python question

Started by February 04, 2004 11:51 AM
1 comment, last by denethor 20 years, 9 months ago
When calling a C function from a Python script, is there any way to determine the name of the calling script. For example: static PyObject* function(PyObject *self, PyObject *args) { ... //need to determine name of python script here ... }
I honestly can''t think of any way, as the flow of information is from module -> executable in Python AFAIK. Would you consider writing a wrapper Python module/function that passes __name__ to the C function as its first (or last, or any other specific position number) argument?
Advertisement
there could never be any built in way of detecting the name of a calling script from the C code ... because how would C even know it was called by python in the first place, let alone what called it ...

In C, the only was for a function to know ANYTHING about the outside world at run time is thorugh calling functions which tell it, looking up global variables, or function parameters ...

obviously there are many many ways you can gather this information yourself, and make it accessable to your C function ...

This topic is closed to new replies.

Advertisement