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

David C Ullrich dullrich at sprynet.com
Mon Aug 10 20:10:14 CEST 2009


What you're trying to do and what's not working isn't 
entirely clear to me.

But if I had a wxPython application and I wanted to
execute user input (note the _if_) I'd just pop up a window
(I forget how "ShowModal" is spelled in wx right now)
with a text box and an Execute button and a Cancel
button - if the user hits the Execute button I'd
attempt to execute what he'd typed in the box.

There are reasons you want to be very careful about
this...

On Mon, 10 Aug 2009 13:44:17 -0400, Rick King wrote:

> 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