Re: How to get all the variables in a python shell
On May 29, 1:47 pm, [EMAIL PROTECTED] wrote: > 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! As an addition: Don't try to share data between windows, it's messy, fragile, and easy to make bugs. PS: Do not confuse Lie (Me) and Lee (OP) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get all the variables in a python shell
On Jun 2, 1:29 am, Lie <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > 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! > > In all kinds of code, it's best to seperate the workers code and the > UI code, in your case, you should create a backend (worker), which is > a class that stands on its own, and two foreground class (UI) that is > completely independent of each other but have the same interface. The > backend code would have an event that is raised when it is changed to > notify the UI (esp. The gui one) that it has changed since last time, > possibly passing info on what have been changed. The front ends, would > watch for this event as necessary (I don't think it is necessary for > the command line to watch this event) and react to it as necessary > like refreshing the view. The front-end window may only call functions > on the backend to interact with the data being worked on (in short the > backend class is opaque). > > This obliviate the need to share data between the two (or more) > windows (UI) because all the data are contained in the backend class > that the frontend can't access directly. To clarify what I meant, the front ends should never contain any working data except the ones needed for the UI to illustrate what it wanted to show at the moment, and even then, it is accessed in read only fashion. And actually because of Python's Global Interpreter Lock, which means that your program would all be contained in the same python interpreter instance (unless you do some workarounds), passing objects/ lists around between python program is cheap because they're just a "reference" passing (like pointer passing in C/C++) This approach is a simple "server-client" method (not a true server- client method though, since a true one cannot share unserialized data), and is extremely scalable, it's easy to add a third window for example, there is no need for every front end to be aware that there are other front ends, since it just watches for the "Changed" event from the backend. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get all the variables in a python shell
[EMAIL PROTECTED] wrote: > 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! In all kinds of code, it's best to seperate the workers code and the UI code, in your case, you should create a backend (worker), which is a class that stands on its own, and two foreground class (UI) that is completely independent of each other but have the same interface. The backend code would have an event that is raised when it is changed to notify the UI (esp. The gui one) that it has changed since last time, possibly passing info on what have been changed. The front ends, would watch for this event as necessary (I don't think it is necessary for the command line to watch this event) and react to it as necessary like refreshing the view. The front-end window may only call functions on the backend to interact with the data being worked on (in short the backend class is opaque). This obliviate the need to share data between the two (or more) windows (UI) because all the data are contained in the backend class that the frontend can't access directly. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get all the variables in a python shell
I'm not certain if this is what you want but try this for the first window: import __main__ localvars = __main__.__dict__ dir(localvars) # lists names of all objects available to the interpreter. And then you can pass localvars anywhere in the program - so after a command is entered in one window, you can import the all locals into the other by putting this function in the second window: def SetWindow2Locals(localvars): __main__.__dict__ = localvars and do the reverse by sending the updated localvars from window 2 to window 1. Setting up an object between the 2 windows should be enough: # window 1, must be created first import __main__ localvars = __main__.__dict__ # create second window (say, win2) win2.SetLocals(localvars) in win2 after creation, there is a method/function: SetLocals(localvars): __main__.__dict__ = localvars If you want to store the object in something like a DB, you can store this localvars dictionary rather than the actual objects. This should be efficient because it stores the object name and ID only but not the objects themselves. However, if the objects are deleted, after saving and before re-loading, you may get some odd results but I'm not sure. I would be very careful of using this in the wild. You can also add objects singly to the dictionary by hand with a function: def importobject(obj): __main__.__dict__[obj.__name__] = obj Which should make them available in the other window easily. If a new object is added to the __main__.__dict__, just grab it and send it to this function. Make sure that you send the object and not just its name because the name is only a string. Sorry if this is not what you were after. Alan On May 29, 2:47 pm, [EMAIL PROTECTED] wrote: > 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! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get all the variables in a python shell
Have you seen this page? http://matplotlib.sourceforge.net/screenshots.html On watching this, I wouldn't say matplotlib is inferior to matlab plotting. Also, I don't know what they use in sage, but they have 3D plots of surfaces that you can rotate with the mouse. Do as you like, but if you want to "intergrate as many exsiting computation libraries as possible" you may end up doing something too similar to sage. I wouldn't want to go on such a trip alone, so even if sage is not exactly what I would do, I will probably work with them. Their client-server approach should make it easy to work on a cool interface without messing too much with their code. It's true, you'll have to carry with you a lot of symbolic computation tools that may be you don't need as an engineer, but is it that important? The client-server approach has other advantages: if you have a very lightweight computer (like EEE), you can place the server at home and the lightweight computer is enough to have a full scientific environment outdoors. And yes, I'm pretty sure you can call any library from within sage the same way you'd do it from python. Regards Pablo -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get all the variables in a python shell
I meant it prints 4, which means the value of test is modified by the access to the dict > test=5 > __IPYTHON__.user_ns['test']=4 > print test #prints 4 > -- http://mail.python.org/mailman/listinfo/python-list
RE: How to get all the variables in a python shell
Hi, thank your for your reply. I will try iPython. I did try sage for a while, but I found it quite heavy, and I'm not sure whether it's easy to expand like python or not. New libraries can be easily imported in python, and those libraries could be build in almost any popular computer language. Can sage do that? The reason why I want to work on this is the same with you. I'm an automotive engineer. What I need is a powerful yet light-weight computation software, which can help me in analyzing datas on the engine test bench. Matlab is powerful, but it contains so much stuff that I actually don't need but have to buy, and you know that it's quite expansive. So my idea is to build a GUI with python first, and then intergrate as many exsiting computation libraries as possible. There also has to be a plotting app, which is quite important and need to think about. I did try Gnuplot-python combination and matplotlib, but found both terrible inferior to Matlab plotting functionality. Do you know any plotting programs written in python? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Friday, May 30, 2008 9:55 PM To: python-list@python.org Subject: Re: How to get all the variables in a python shell 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? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get all the variables in a python shell
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? -- http://mail.python.org/mailman/listinfo/python-list
Re: [python-win32] How to get all the variables in a python shell
[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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: [python-win32] How to get all the variables in a python shell
Tim Golden wrote: [EMAIL PROTECTED] 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/ -- http://mail.python.org/mailman/listinfo/python-list
RE: [python-win32] How to get all the variables in a python shell
-Original Message- From: Paul Moore [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2008 7:23 AM To: Dahlstrom, Roger Cc: Python-Win32 List; python-list@python.org Subject: Re: [python-win32] How to get all the variables in a python shell On 29/05/2008, Dahlstrom, Roger <[EMAIL PROTECTED]> 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: [python-win32] How to get all the variables in a python shell
On 29/05/2008, Dahlstrom, Roger <[EMAIL PROTECTED]> 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. -- http://mail.python.org/mailman/listinfo/python-list
RE: [python-win32] How to get all the variables in a python shell
-Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tim Golden > Sent: Thursday, May 29, 2008 4:11 AM > To: Python-Win32 List; python-list@python.org > Cc: Python-Win32 List > Subject: Re: [python-win32] How to get all the variables in a python shell > > [EMAIL PROTECTED] 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 > [EMAIL PROTECTED] > 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get all the variables in a python shell
[EMAIL PROTECTED] 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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get all the variables in a python shell
[EMAIL PROTECTED] 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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get all the variables in a python shell
On 2008-05-29, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > 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 -- http://mail.python.org/mailman/listinfo/python-list
How to get all the variables in a python shell
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! -- http://mail.python.org/mailman/listinfo/python-list