Why cannot jump out the loop?

Mark McEahern marklists at mceahern.com
Thu Apr 29 22:44:33 EDT 2004


Sorry for top-posting:  I just wanted to add that in the OP's case, what 
he really needs is for not while.

import sys
n = int(sys.argv[1])
for i in range(n):
    print locals()

// m

p.s.  Others have already noted that sys.argv returns a sequence of strings.

>    Jinming> I have a very simple python program, which includes a while
>    Jinming> loop. But to my surprise, it cannot jump out the while
>    Jinming> loop. Does anyone know why?
>
>    Jinming> Here is the program:
>    Jinming> ___________________________
>    Jinming> #!/usr/bin/env python
>    Jinming> import sys
>    Jinming> n=sys.argv[1]
>    Jinming> i=0
>    Jinming> while i<n:
>    Jinming>   print "i=",i," n=",n
>    Jinming>   i+=1
>    Jinming> -----------------------------------------------------
>





More information about the Python-list mailing list