Why is it not possible to get the frame from the interpreter using the
inspect library? IOW, why does this code: from inspect import * stack()
produce:
[(<frame object at 0x81b6d94>, '<stdin>', 1, '?', None, None)]
instead of:
[(<frame object at 0x81b6d94>, '<stdin>', 1, '?', '\tstack()', 0)]
?
I must be missing something. The motivating question is:
How can I get the interpreter line that triggered the current actions?
TIA,
Leo. 5 1304
Leo wrote: Why is it not possible to get the frame from the interpreter using the inspect library?
Because sys._getframe() does the job instead?
-Peter
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. Here is the output of sys._getframe() on my system:
Python 2.3.4 (#1, Feb 2 2005, 12:11:53)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information. import sys sys._getframe()
<frame object at 0x9fbce0c> from inspect import * getframeinfo(sys._getframe())
('<stdin>', 1, '?', None, None)
Is it different in 2.4? Maybe there is something else in sys.* that I
am having trouble finding?
TIA,
Leo.
On 10 Aug 2005 15:08:21 -0700, "Leo" <le*****@gmail.com> 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. Here is the output of sys._getframe() on my system:
Python 2.3.4 (#1, Feb 2 2005, 12:11:53) [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. import sys sys._getframe()<frame object at 0x9fbce0c> from inspect import * getframeinfo(sys._getframe())
('<stdin>', 1, '?', None, None)
Is it different in 2.4? Maybe there is something else in sys.* that I am having trouble finding?
Isn't there some requirement of having a source file in order to get
the line of code, which an interactive session does not satisfy?
(Maybe a strategically located StringIO instance encapsulating the latest
interactive chunk as "source file" could solve it?)
Regards,
Bengt Richter
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...
-Peter
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jon Perez |
last post by:
When you run an empty while loop under Python , it slows
down the rest of the system. Is this normal? And should
it be something that needs to be corrected?
|
by: Rolf Magnus |
last post by:
Hi,
I would like to embed a python interpreter within a program, but since that
program would be able to automatically download scripts from the internet,
I'd like to run those in a restricted...
|
by: Miki Tebeka |
last post by:
Hello All,
If there a way a script can tell Python to enter interactive mode even if
the -i command line switch was not given?
I want py2exe to create an interactive session, without writing...
|
by: gr |
last post by:
hi.. I must implement an interpreter in C programming language that
will get the source code of a program in text file format and execute
it.
but i don't know C language enough to write this...
|
by: Robin Becker |
last post by:
As part of some django usage I need to get some ReportLab C extensions into a
state where they can be safely used with mod_python.
Unfortunately we have C code that seems incompatible with...
|
by: nadeemabdulhamid |
last post by:
Hello,
I'm trying to write some Java code that will launch a python
interpreter shell and pipe input/output back and forth from the
interpreter's i/o streams and the Java program. The code posted...
|
by: jkimbler |
last post by:
As part of our QA of hardware and firmware for the company I work for,
we need to automate some testing of devices and firmware. Since not
everybody here knows C#, I'm looking to create a new...
|
by: castironpi |
last post by:
I'm curious about some of the details of the internals of the Python
interpreter:
I understand C from a hardware perspective.
x= y+ 1;
Move value from place y into a register
Add 1 to the...
|
by: cnb |
last post by:
I'm trying to switch to using emacs for python.
The interpreter and python-mode works but I can't load the file I'm
editing into the interpreter.
im not sure if c-c c-l is supposed to do that...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |