The next release of pydb will have the ability to go into ipython from
inside the debugger. Sort of like how in ruby-debug you can go into
irb :-)
For ipython, this can be done pretty simply; there is an IPShellEmbed
method which returns something you can call. But how could one do the
same for the stock python interactive shell?
To take this out of the realm of debugging. What you want to do is to
write a python program that goes into the python interactive shell -
without having to write your own a read/eval loop and deal with
readline, continuation lines, etc.
The solution should also allow
- variables/methods in the calling PYthon program to be visible
in the shell
- variables set in the interactive (sub) shell should persist after the shell
terminates, although this is a weaker requirement. POSIX subshells
for example *don't* work this way.
There has been much written about how to embed Python from C, so I
suppose this may offer one way. And at worst, I could write
a C extension which follows how C Python does this for itself.
But is there a simpler way?
Thanks. 3 1824
I'm not sure if this is exactly what you're after, but try looking
into the 'code' module.
It's fairly easy to make an interactive interpreter that runs within
your program. If you import your programs variables into
__main__.__dict__, you can have access to them which can be funky. You
can even override the showtraceback method to catch various exceptions
and do daft things like adding new methods to strings. I guess it
would even be possible to have the commands compared to a list of
commands and keywords to build a restricted interpreter, though how
secure this would be against a determined attack is another matter.
Alan
On May 15, 11:31 am, ro...@panix.com (R. Bernstein) wrote:
The next release of pydb will have the ability to go into ipython from
inside the debugger. Sort of like how in ruby-debug you can go into
irb :-)
For ipython, this can be done pretty simply; there is an IPShellEmbed
method which returns something you can call. But how could one do the
same for the stock python interactive shell?
To take this out of the realm of debugging. What you want to do is to
write a python program that goes into the python interactive shell -
without having to write your own a read/eval loop and deal with
readline, continuation lines, etc.
The solution should also allow
- variables/methods in the calling PYthon program to be visible
in the shell
- variables set in the interactive (sub) shell should persist after the shell
terminates, although this is a weaker requirement. POSIX subshells
for example *don't* work this way.
There has been much written about how to embed Python from C, so I
suppose this may offer one way. And at worst, I could write
a C extension which follows how C Python does this for itself.
But is there a simpler way?
Thanks.
"Alan J. Salmoni" <sa*****@gmail.comwrites:
I'm not sure if this is exactly what you're after, but try looking
into the 'code' module.
It's fairly easy to make an interactive interpreter that runs within
your program. If you import your programs variables into
__main__.__dict__, you can have access to them which can be funky. You
can even override the showtraceback method to catch various exceptions
and do daft things like adding new methods to strings. I guess it
would even be possible to have the commands compared to a list of
commands and keywords to build a restricted interpreter, though how
secure this would be against a determined attack is another matter.
Alan
I think this (largely) does the trick. Thanks!
I'm not sure about how to deal with globals yet which should come from
a stackframe f_globals. It might be possible to save and restore
__main__.__dict__ before and after the call to interact(). Probably
would have been cooler to design interact() to take a globals
parameter, same as eval does.
>
On May 15, 11:31 am, ro...@panix.com (R. Bernstein) wrote:
>The next release of pydb will have the ability to go into ipython from inside the debugger. Sort of like how in ruby-debug you can go into irb :-)
For ipython, this can be done pretty simply; there is an IPShellEmbed method which returns something you can call. But how could one do the same for the stock python interactive shell?
To take this out of the realm of debugging. What you want to do is to write a python program that goes into the python interactive shell - without having to write your own a read/eval loop and deal with readline, continuation lines, etc.
The solution should also allow - variables/methods in the calling PYthon program to be visible in the shell - variables set in the interactive (sub) shell should persist after the shell terminates, although this is a weaker requirement. POSIX subshells for example *don't* work this way.
There has been much written about how to embed Python from C, so I suppose this may offer one way. And at worst, I could write a C extension which follows how C Python does this for itself.
But is there a simpler way?
Thanks.
On May 15, 6:26*am, ro...@panix.com (R. Bernstein) wrote:
"Alan J. Salmoni" <salm...@gmail.comwrites:
I'm not sure if this is exactly what you're after, but try looking
into the 'code' module.
It's fairly easy to make an interactive interpreter that runs within
your program. If you import your programs variables into
__main__.__dict__, you can have access to them which can be funky. You
can even override the showtraceback method to catch various exceptions
and do daft things like adding new methods to strings. I guess it
would even be possible to have the commands compared to a list of
commands and keywords to build a restricted interpreter, though how
secure this would be against a determined attack is another matter.
Alan
I think this (largely) does the trick. Thanks!
I'm not sure about how to deal with globals yet which should come from
a stackframe f_globals. It might be possible to save and restore
__main__.__dict__ before and after the call to interact(). Probably
would have been cooler to design interact() to take a globals
parameter, same as eval does.
On May 15, 11:31 am, ro...@panix.com (R. Bernstein) wrote:
The next release of pydb will have the ability to go into ipython from
inside the debugger. Sort of like how in ruby-debug you can go into
irb :-)
For ipython, this can be done pretty simply; there is an IPShellEmbed
method which returns something you can call. But how could one do the
same for the stock python interactive shell?
To take this out of the realm of debugging. What you want to do is to
write a python program that goes into the python interactive shell -
without having to write your own a read/eval loop and deal with
readline, continuation lines, etc.
The solution should also allow
*- variables/methods in the calling PYthon program to be visible
* *in the shell
*- variables set in the interactive (sub) shell should persist after the shell
* *terminates, although this is a weaker requirement. POSIX subshells
* *for example *don't* work this way.
There has been much written about how to embed Python from C, so I
suppose this may offer one way. And at worst, I could write
a C extension which follows how C Python does this for itself.
But is there a simpler way?
Thanks.- Hide quoted text -
- Show quoted text -
One threat is malicious code; sorry for this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: leroybt.rm |
last post by:
I don't understand why this does not work:
<FILE1> test1.py
#Import Packages
import string
#
data=0
data=data+1
|
by: Sateesh |
last post by:
Hi,
I am a beginner in Python, and am wondering what is it about the indentation
in Python, without which python scripts do not work properly.
Why can't the indentation not so strict so as to give...
|
by: Avi Berkovich |
last post by:
Hello,
I was unable to use popen2.popen4 to grab python.exe's (2.3) output, for
starts, it doesn't show the version information at the beginning and
won't return anything when writing to the...
|
by: Paul Cochrane |
last post by:
Hi all,
I've got an application that I'm writing that autogenerates python code
which I then execute with exec(). I know that this is not the best way to
run things, and I'm not 100% sure as to...
|
by: dmh2000 |
last post by:
I am experimenting with the interactive interpreter environments of
Python and Ruby and I ran into what seems to be a fundamental
difference. However I may be doing something wrong in Python....
|
by: linuxnow |
last post by:
I don't know what I'm doing wrong, but the result is that _import_ only
works from a python shell, but not when I call a python script.
$ cat test.py
mod = __import__("/home/me/tests/test_imp")...
|
by: notejam |
last post by:
I am trying to get started with a interactive version of Python for
windows and need some help.
I have played with the tutorial, and now want to write a program.
In basic language, I could write...
|
by: Simon Eves |
last post by:
I am trying to write a Python module to embed the functionality of
Maya (the 3D modelling and animation application from Autodesk,
formerly Alias) for doing scripted scene manipulation and...
|
by: yan.python |
last post by:
i have a question.
when i run Interactive Interpreter in linux command promt,how can i
move the cursor.
for example,when i enter a string,i often enter the quotation mark ""
first,and the move...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |