[Tutor] providing a Python command line within a Tkinter appl

Tiger12506 keridee at jayco.net
Wed Jan 2 20:35:38 CET 2008


eval will seriously limit you in this instance because eval only works on 
expressions, not statements. (Assignment won't work, for example). You can 
use exec though. (in which case, you wouldn't necessarily want a result 
back)

just fyi

> text =my_get_pythoncommand()   # text is the line of text entered in
> the window by the user
> try:
>   result=eval(text)
>   my_print_pythoncommand_result(result) # echoing the result of the
> command back to the user
> except error1:
>   some error message
> except error2:
>   some other error message
> except error3:
>   ... etc ...
> except:
>   some generic error message for unrecognised errors
>
> The question is does this make sense or is there an easier way,
> particularly one where I'd be able to get the same error messages
> provided by the command line python interpreter?
>
> I guess the other question I have is if this the way to go, are there
> any gotchas re the Python code I can execute in this way. Remember I
> am trying to provide a means of doing analyses  that are not provided
> by the framework so it would nice to just say to the user "Enter
> anything that is valid Python ... just like in the Python interpreter
> or IDLE".
>
>
> ====================================================================
> Prof Garry Willgoose,
> Australian Professorial Fellow in Environmental Engineering,
> Director, Centre for Climate Impact Management (C2IM),
> School of Engineering, The University of Newcastle,
> Callaghan, 2308
> Australia.
>
> Centre webpage: www.c2im.org.au
>
> Phone: (International) +61 2 4921 6050 (Tues-Fri AM); +61 2 6545 9574
> (Fri PM-Mon)
> FAX: (International) +61 2 4921 6991 (Uni); +61 2 6545 9574 (personal
> and Telluric)
> Env. Engg. Secretary: (International) +61 2 4921 6042
>
> email:  garry.willgoose at newcastle.edu.au;
> g.willgoose at telluricresearch.com
> email-for-life: garry.willgoose at alum.mit.edu
> personal webpage: www.telluricresearch.com/garry
> ====================================================================
> "Do not go where the path may lead, go instead where there is no path
> and leave a trail"
>                           Ralph Waldo Emerson
> ====================================================================
>
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



More information about the Tutor mailing list