Peter Hansen wrote: > Leo wrote: >> Good try, but that doesn't seem to work either. Maybe I should have >> emphasized that what I really want is the line of code, as opposed to >> the entire frame. > > Ah, it wasn't clear from your first post that you were specifically > interested in a line you entered at the *interactive prompt*. The word > "interpreter" is sometimes applied to the virtual machine, so I thought > you just wanted the current frame inside an application. > > For the "interactive interpreter", I doubt the line of code that you are > executing is preserved anywhere (at least not in a supported, documented > fashion) as source, so I don't think there's a simple way to get at it. > Certainly not (I believe) through the frame or code object. Maybe > checking the source will lead to a hack solution...
If using the mock interpreter in code.py (in the stdlib), the object's .buffer attribute holds that info as a list of lines. IPython exposes it publicly via its custom exception handlers mechanism (some details here: http://www.scipy.org/wikis/featurerequests/IPython). Such a buffer must also exist in the CPython interactive interpreter, but I don't think it's accessible in any way via Python-level functionality (it's most likely an internal C variable). But some perusing of the C sources could indicate a way to get to it, I'm just not familiar with that particular code. Cheers, f -- http://mail.python.org/mailman/listinfo/python-list