Newbie: needs help with ...

Terry Hancock hancock at anansispaceworks.com
Thu Nov 7 22:46:44 EST 2002


On Thursday 07 November 2002 07:26 pm, python-list-request at python.org wrote:
> I'm trying to print the contents of a list.
> 
> Python displays "..." until I press enter. Why is it waiting for me to 
press enter ?
> 
> >>> for x in l2[:5] : print x
> ...

I'm not exactly sure whether:

for x in l2[:5]: print x
    print x, x

would be legal (it's certainly bad style), so maybe the
interpreter ought to figure out that there won't be anything
more in the loop.  But what the "..." is about is the way the
interactive interpreter decides when a loop is actually
complete:

>>> if x in l2[:5]:
...        print x
...        print "x = %d" % x
...

That last "..." with no content tells the interpreter you're done
so it can actually run the loop.  (So you can't have any
blank lines when you're pasting code into the interpreter
to test it, and each loop must have a blank line as well as
a dedent). 

This is a difference between the interactive and  script
modes of operation of python.  You see the same thing with
tcsh and bash, BTW (though the prompt symbols are
different).

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list