如何获取python shell中的所有变量 [英] How to get all the variables in a python shell

查看:117
本文介绍了如何获取python shell中的所有变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


我正在研究用
python构建的科学计算软件。

我是什么想要实现的是一个Matlab样式命令窗口< - >

工作空间交互。


例如,你输入''a = 1''命令窗口,你看到一个列表

项目在工作区中名为''a''。

你双击项目的图标,你看到它的价值。您可以

修改列表项的值,

1 -100等,之后如果你回到命令窗口并且

输入''a'并按回车键,你会看到

varable a'的值已经改为100.


所以我的问题是:如果你有两个DOS命令窗口在

WINDOWS OS下运行,你怎么能让它们共享相同的内部变量

buffer?或者有没有更简单的方法来实现这种类型的

交互?


也许我可以构建一个小型数据库来存储所有值并且

从这两个程序中访问它们,但有时我可能需要处理大数组,并且如果我将它们保留在内,它们将会消耗额外的内存

a数据库。反正有没有访问shell的本地内存缓冲区?

我试图在wxPython中使用shell.interp.locals(),但是太多了

列表中我不需要的变量。


来吧伙计们,给我一些想法。提前致谢!

解决方案

2008-05-29, li ******** @ gmail.com < li ******** @ gmail.comwrote:


嗨!


我正在研究用
python构建的科学计算软件。

我是什么想要实现的是一个Matlab样式命令窗口< - >

工作空间交互。



ok,虽然我个人赞成编写和运行

脚本/程序的风格,因为它可以更好地扩展(你可以更容易自动化步骤),

,它更容易重现(你可能想要的科学

软件)和可存储(在VCS中)。


例如,在命令窗口中键入a = 1,然后在工作区中看到一个名为a的
项列表。

双击项目图标,即可看到其值。您可以

修改列表项的值,

1 -100等,之后如果你回到命令窗口并且

输入a然后按回车键,你会看到

varable a'的值已经改为100.



I希望你已经公平估计了它所花费的工作量

以这种方式改变变量的价值。


我会建议简单地使用交互式Python提示。它没有给你点击弹出图标,但你确实得到了整个Python解释器,并且免费获得了所有库的



Python库有一个用于自定义解释器的框架。有一个

看看''cmd''模块。


所以我的问题是:如果你有两个DOS命令窗口在

WINDOWS操作系统,如何让它们共享相同的内部变量

缓冲区?或者有没有更简单的方法来实现这种类型的

互动?



现在你失去了我。一个窗口不足以进行交互?


显然,你需要一个通用的解释器/存储后端。一个

解决方案可能是有一个共同的执行后端,并且每个窗口都有一个

''前端'',它传递输入到后端的命令,以及从后端到终端回应结果



也许我可以构建一个小型数据库来存储所有值并且<从两个程序中获取
,但有时候我不得不用
处理大数组,如果我将它们保存在
中,他们会吃额外的内存



当你将它们保存在数据库中时,它们会占用内存吗?看来,你在没有告诉他们的情况下对这里的实现进行了假设。

(即选择使用磁盘的数据库,你的问题就解决了。为什么会这样

不是一个选项?)


真诚的,

Albert


li********@gmail.com 写道:


我正在研究用
python构建的科学计算软件。

我想要实现的是Matlab样式命令窗口< - >

工作区交互。


例如,在命令窗口中键入a = 1,你看到一个清单

在工作区中命名为''a'的项目。

你双击项目的图标,然后看到它的值。您可以

修改列表项的值,

1 -100等,之后如果你回到命令窗口并且

输入''a'并按回车键,你会看到

varable a'的值已经改为100.


所以我的问题是:如果你有两个DOS命令窗口在

WINDOWS OS下运行,你怎么能让它们共享相同的内部变量

buffer?或者有没有更简单的方法来实现这种类型的

互动?



我强烈建议你看一下IPython [1]。为了做我认为你想要描述的内容,你需要破解或重新实现翻译。

这就是他们所做的。 ISTR,他们甚至有一个分支

处理并行实例。


TJG


[1] http://ipython.scipy.org/moin/


li********@gmail.com 写道:


我正在研究用
python构建的科学计算软件。

我是什么想要实现的是一个Matlab样式命令窗口< - >

工作空间交互。


例如,你输入''a = 1''命令窗口,你看到一个列表

项目在工作区中名为''a''。

你双击项目的图标,你看到它的价值。您可以

修改列表项的值,

1 -100等,之后如果你回到命令窗口并且

输入''a'并按回车键,你会看到

varable a'的值已经改为100.


所以我的问题是:如果你有两个DOS命令窗口在

WINDOWS OS下运行,你怎么能让它们共享相同的内部变量

buffer?或者有没有更简单的方法来实现这种类型的

互动?



我强烈建议你看一下IPython [1]。为了做我认为你想要描述的内容,你需要破解或重新实现翻译。

这就是他们所做的。 ISTR,他们甚至有一个分支

处理并行实例。


TJG


[1] http://ipython.scipy.org/moin/


Hi!

I''m currently working on a scientific computation software built in
python.
What I want to implement is a Matlab style command window <->
workspace interaction.

For example, you type ''a=1'' in the command window, and you see a list
item named ''a'' in the workspace.
You double click the icon of the item, and you see its value. You can
modify the value of the list item,
1 -100 etc, after which if you go back to the command window and
type ''a'' and press enter, you see that
varable a''s value has been changed to 100.

So my question is : if you have two DOS command windows running under
WINDOWS OS, how can you make them share the same internal variable
buffer? Or is there any easier way to implement such kind of
interaction?

Maybe I could just build a small database to store all the values and
access them from both programs, but chances are sometimes I have to
deal with big arrays, and they will eat extra memory if I keep them in
a database. Is there anyway to access a shell''s local memory buffer?
I tried to use shell.interp.locals() in wxPython, but there''s too many
variables in the list which I don''t actually need.

Come on guys, give me some ideas. Thanks in advance!

解决方案

On 2008-05-29, li********@gmail.com <li********@gmail.comwrote:

Hi!

I''m currently working on a scientific computation software built in
python.
What I want to implement is a Matlab style command window <->
workspace interaction.

ok, although I personally favor the style of writing and running a
script/program, since it scales much better (you can easier automate steps),
and it is much easier reproducible (something you probably want in scientific
software) and storable (in a VCS).

For example, you type ''a=1'' in the command window, and you see a list
item named ''a'' in the workspace.
You double click the icon of the item, and you see its value. You can
modify the value of the list item,
1 -100 etc, after which if you go back to the command window and
type ''a'' and press enter, you see that
varable a''s value has been changed to 100.

I do hope you have made a fair estimate of the amount of work that it costs to
change the value of a variable in this way.

I would propose to simply use the interactive Python prompt. It doesn''t give
you popup icons for clicking, but you do get the entire Python interpreter, and
all its libraries for free.

The Python library has a frame work for customizing the interpreter. Have a
look at ''cmd'' module.

So my question is : if you have two DOS command windows running under
WINDOWS OS, how can you make them share the same internal variable
buffer? Or is there any easier way to implement such kind of
interaction?

Now you have lost me. One window is not enough for interaction?

Obviously, you''ll need to have a common interpreter/storage backend. One
solution may be to have a common execution back-end, and for each window a
''frontend'' which passes commands entered to the back-end, and echoes results
from the back-end to the terminal.

Maybe I could just build a small database to store all the values and
access them from both programs, but chances are sometimes I have to
deal with big arrays, and they will eat extra memory if I keep them in

They eat memory when you keep them in a data base? It seems, you are making
assumptions about implementations here without telling them.
(ie pick a data base that uses a disk, and your problem is solved. Why is that
not an option?)

Sincerely,
Albert


li********@gmail.com wrote:

I''m currently working on a scientific computation software built in
python.
What I want to implement is a Matlab style command window <->
workspace interaction.

For example, you type ''a=1'' in the command window, and you see a list
item named ''a'' in the workspace.
You double click the icon of the item, and you see its value. You can
modify the value of the list item,
1 -100 etc, after which if you go back to the command window and
type ''a'' and press enter, you see that
varable a''s value has been changed to 100.

So my question is : if you have two DOS command windows running under
WINDOWS OS, how can you make them share the same internal variable
buffer? Or is there any easier way to implement such kind of
interaction?

I stronly suggest you look at IPython [1]. To do what I think
you''re describing, you''d need to hack or reimplement the interpreter.
And that''s what they''ve done. ISTR that they even have a branch
which is dealing with parallel instances.

TJG

[1] http://ipython.scipy.org/moin/


li********@gmail.com wrote:

I''m currently working on a scientific computation software built in
python.
What I want to implement is a Matlab style command window <->
workspace interaction.

For example, you type ''a=1'' in the command window, and you see a list
item named ''a'' in the workspace.
You double click the icon of the item, and you see its value. You can
modify the value of the list item,
1 -100 etc, after which if you go back to the command window and
type ''a'' and press enter, you see that
varable a''s value has been changed to 100.

So my question is : if you have two DOS command windows running under
WINDOWS OS, how can you make them share the same internal variable
buffer? Or is there any easier way to implement such kind of
interaction?

I stronly suggest you look at IPython [1]. To do what I think
you''re describing, you''d need to hack or reimplement the interpreter.
And that''s what they''ve done. ISTR that they even have a branch
which is dealing with parallel instances.

TJG

[1] http://ipython.scipy.org/moin/


这篇关于如何获取python shell中的所有变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆