NumTut view of greece

Gary Herron gherron at islandtraining.com
Sun May 7 12:21:41 EDT 2006


Gary Wessle wrote:

>Hi
>
>not sure if this would be the right place to ask this question!
>using the shell prompt 
>:~$ python
>Python 2.3.5 (#2, Mar  6 2006, 10:12:24) 
>[GCC 4.0.3 20060304 (prerelease) (Debian 4.0.2-10)] on linux2
>Type "help", "copyright", "credits" or "license" for more information.
>  
>
>>>>import Numeric
>>>>from NumTut import *
>>>>view(greece)
>>>>
>>>>        
>>>>
>shows a photo of the street in a tk window.
>
>but if I have this file
>**************** tut.py ****************
>#!/usr/bin/env python
>import Numeric
>from NumTut import *
>view(greece)
>print "done"
>****************************************************************
>and then type
>$ ./tut.py
>done
>$
>and not tk view of greece.
>  
>
That's because, as soon as the program quits, the view window is removed.

In your interactive example, the view command opens the window, and then 
immediately starts waiting for you to type the next command. Python is 
still running and so the view window stays up.

In the non-interactive case, as soon as the view command executes, 
Python immediately goes to the next line, does the print, then exits. 
The view command, which was busily preparing to show your picture is 
shut down when python exits before it had enough time to open the 
window. (It was trying -- it just didn't have enough time.)

If you don't want the program to quit that quickly, you need to put in 
something to keep it from running off the bottom and exiting. I'd 
suggest something like this after the view line:

raw_input("Type ENTER when done viewing: ")

Gary Herron


>thanks
>  
>




More information about the Python-list mailing list