inspect: get the calling command

Inyeol Lee inyeol.lee at siimage.com
Tue Jun 15 12:03:47 EDT 2004


On Tue, Jun 15, 2004 at 09:36:34AM +0200, Hans Georg Krauthaeuser wrote:
...
> Thanks for pointing me there. Resolution for this bug is 'Wont Fix'. So, 
> did you have any idea how to work around that 'feature'.

This is what I was doing. There might be better way.

1. get caller's source code using inspect.getsourcelines(traceback).
   (Above function has a bug dealing with module-level traceback in
   2.3.3. I'm not sure if it's fixed now.)
2. Tokenize the source up to traceback.tb_lineno.
3. Scan for last logical line break (token.NR ?).

> BTW, are you sure that my problem is really due to that bug. I'm asking 
> because one comment stated: '...You should also check out current CVS, 
> seeing as there are no SET_LINENO instructions any more...'

Python 2.3.3 has the same bug (feature?). I didn't try 2.3.4.
2.3 doesn't use SET_LINENO bytecode, but uses traceback.tb_lineno instead.
It shows the same behavior.

Inyeol




More information about the Python-list mailing list