On Jul 15, 2011, at 11:59 PM, Campbell Barton firstname.lastname@example.org wrote:
Hi Enrico, Officially, I think what you want to do isn't really supported by python.
Which is exactly the scenario I envision, unfortunately.
In practice you can probably manage it if make a few assumptions.
You can access these attributes (or their C values directly): myfunc.__code__.co_filename myfunc.__code__.co_firstlineno
However these are not going to help me if the function data comes from standard input instead of from a file
Personally I'd not worry about the PyCodeObject changing (though without more details on what you do its hard to say).
Or you could import the 'inspect' module via the C api and call its getsource() function, however 'inspect' just makes a guess too and isn't guaranteed to give the correct result, this at least gets around changes in PyCodeObject but assumes a full python installation.
I guess this is not viable either, still thanks a lot for your helpful hints.
capi-sig mailing list email@example.com http://mail.python.org/mailman/listinfo/capi-sig