Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to get all the variables in a python shell

Reply
Thread Tools

How to get all the variables in a python shell

 
 
lixinyi.23@gmail.com
Guest
Posts: n/a
 
      05-29-2008
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!
 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      05-29-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) 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/
 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      05-29-2008
(E-Mail Removed) 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/
 
Reply With Quote
 
Dahlstrom, Roger
Guest
Posts: n/a
 
      05-29-2008
-----Original Message-----
> From: (E-Mail Removed) [mailto(E-Mail Removed)] On Behalf Of Tim Golden
> Sent: Thursday, May 29, 2008 4:11 AM
> To: Python-Win32 List; (E-Mail Removed)
> Cc: Python-Win32 List
> Subject: Re: [python-win32] How to get all the variables in a python shell
>
> (E-Mail Removed) 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-win32 mailing list
> (E-Mail Removed)
> http://mail.python.org/mailman/listinfo/python-win32



I'd try looking at memcached (http://www.danga.com/memcached/apis.html). No hacking or reimplementation of the interpreter would be necessary, and there's a
Python api available. I haven't used it for anything production related, but I have played with it a bit, and it's fast and stable.



DISCLAIMER:
This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and
may contain legally privileged and/or confidential information. If you are not the intended recipient
of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and
any attachments thereto, is strictly prohibited. If you have received this in error, please immediately notify
me and permanently delete the original and any copy of any e-mail and any printout thereof.
E-mail transmission cannot be guaranteed to be secure or error-free. The sender therefore does not accept
liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission.

NOTICE REGARDING PRIVACY AND CONFIDENTIALITY
Direct Edge ECN LLC may, at its discretion, monitor and review the content of all e-mail communications.

www.directedge.com
 
Reply With Quote
 
Paul Moore
Guest
Posts: n/a
 
      05-29-2008
On 29/05/2008, Dahlstrom, Roger <(E-Mail Removed)> wrote:
> I'd try looking at memcached (http://www.danga.com/memcached/apis.html).
> No hacking or reimplementation of the interpreter would be necessary, and
> there's a Python api available. I haven't used it for anything production related,
> but I have played with it a bit, and it's fast and stable.


Is memcached available for Windows, then? I've heard nice things about
it, but thought it was Unix-only.

Paul.
 
Reply With Quote
 
Dahlstrom, Roger
Guest
Posts: n/a
 
      05-29-2008
-----Original Message-----
From: Paul Moore [mailto(E-Mail Removed)]
Sent: Thursday, May 29, 2008 7:23 AM
To: Dahlstrom, Roger
Cc: Python-Win32 List; (E-Mail Removed)
Subject: Re: [python-win32] How to get all the variables in a python shell

On 29/05/2008, Dahlstrom, Roger <(E-Mail Removed)> wrote:
> I'd try looking at memcached (http://www.danga.com/memcached/apis.html).
> No hacking or reimplementation of the interpreter would be necessary, and
> there's a Python api available. I haven't used it for anything production related,
> but I have played with it a bit, and it's fast and stable.


Is memcached available for Windows, then? I've heard nice things about
it, but thought it was Unix-only.

Paul.


----------------------------

It is available for Windows, yes. As a matter of fact, I've never used it on Unix.


DISCLAIMER:
This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and
may contain legally privileged and/or confidential information. If you are not the intended recipient
of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and
any attachments thereto, is strictly prohibited. If you have received this in error, please immediately notify
me and permanently delete the original and any copy of any e-mail and any printout thereof.
E-mail transmission cannot be guaranteed to be secure or error-free. The sender therefore does not accept
liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission.

NOTICE REGARDING PRIVACY AND CONFIDENTIALITY
Direct Edge ECN LLC may, at its discretion, monitor and review the content of all e-mail communications.

www.directedge.com
 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      05-29-2008
Tim Golden wrote:
> (E-Mail Removed) 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.


Sorry, having seen Roger D's memcached suggestion, I realise I may
have misinterpreted your requirement. I thought that you wanted
a Python interpreter session to share its objects to another window,
hence my IPython suggestion. If you're writing your own console app
and want to share stuff, then there's any number of IPC possibilities.

Roger's already mentioned memcached which I've no more than a
passing knowledge of. But Pyro [1] is often a good bet for these
things, and the pyprocessing [2] module is gaining a fair bit of
traction at the moment. (To name just two out of many).

TJG

[1] http://pyro.sf.net
[2] http://pyprocessing.berlios.de/

 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      05-29-2008
<<< No Message Collected >>>
 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      05-29-2008
[Bizarrely, my mail system seems to be randomly misfiring.
If you've already seen this, please ignore!]

Tim Golden wrote:
Sorry, having seen Roger D's memcached suggestion, I realise I may
have misinterpreted your requirement. I thought that you wanted
a Python interpreter session to share its objects to another window,
hence my IPython suggestion. If you're writing your own console app
and want to share stuff, then there's any number of IPC possibilities.

Roger's already mentioned memcached which I've no more than a
passing knowledge of. But Pyro [1] is often a good bet for these
things, and the pyprocessing [2] module is gaining a fair bit of
traction at the moment. (To name just two out of many).

TJG

[1] http://pyro.sf.net
[2] http://pyprocessing.berlios.de/

 
Reply With Quote
 
caca@mailinator.com
Guest
Posts: n/a
 
      05-30-2008
Your project interests me. Actually I was thinking about doing the
same. I hadn't worked on it at all, but I though about it and had the
idea about reading the session namespace directly, which I though
would be stored in the __dict__ attribute of something.

After reading your post, I have been trying a little bit, and I have
found a way to do it with ipython. If you open an ipython console,
press _ then hit TAB, you'll see it stores some useful information,
including all input, all output, and after some searching, a
dictionary matching all variables to its values.

__IPYTHON__.user_ns

There is a little extra stuff in there that you don't want, but that
can be easily filtered (the extra stuff is either 'In', 'Out', 'help'
or starts with '_'). I've tried it, and you can change the value in
that dict to alter the value of the real variable. Say you have a
variable 'test':

test=5
__IPYTHON__.user_ns['test']=4
print test #prints 5

If I get it right, python is a dynamic language, and you won't break
things by messing around with its inner stuff like this, but you
better check it.

Is this what you had in mind?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
RE: How to get all the variables in a python shell Lee Python 1 05-31-2008 12:09 PM
Re: How to pass shell variable to shell script from python D'Arcy J.M. Cain Python 0 02-27-2008 01:56 PM
Re: How to pass shell variable to shell script from python Gerardo Herzig Python 1 02-27-2008 12:19 PM
Re: How to pass shell variable to shell script from python Christian Heimes Python 0 02-27-2008 10:53 AM



Advertisments