how to use "exec" stmt to get input from user

Rick King rickbking at comcast.net
Mon Aug 10 13:44:17 EDT 2009


I have a cmd.py-derived program (with a wxPython GUI) and want to 
execute python statements for lines that are not my own special commands.

So basically it's either:

    def do_somecommand(self,arg):
        ...

or

    def default(self,arg):
        exec arg in globals(),self.cmdlocals

(where cmdlocals is a my local dictionary)

in default() I'd like to be able to execute any python statement 
including something like

    "x = raw_input('>')"

when I do this though it goes to the command window and so any user of 
the program would be confused, which also means I have to have a command 
window.

If I add this:

    self.stdin = self.edt_console_input   (where self.edt_console_input 
is a wxPython text control)

it just gets an EOF right away.

Is there any way to do what I want to do? This might be better posted on 
the wxpython list.

Thanks for any help!

Rick King
Southfield MI





More information about the Python-list mailing list