On Thu, Dec 8, 2011 at 7:43 AM, Dario Lopez-Kästen <cl2dl...@gmail.com>wrote:

> <snip>
>
> In that case a for loop with a try-except would better:
>
> strNum = raw_input("enter numbers, separated by space: ").split()
> num_list = []
>
> for token in strNum:
>     try:
>         num_list.append(int(token))
>     except ValueError:
>         # Do nothing, fetch the next token
>         continue
>
> print repr(num_list)
> <snip>
> Strictly speaking the "continue" in the except clause is not necessary in
> this simple example.
>

Though you do have to have *something* or you'll get a syntax error because
you can't have an empty block. The keyword `pass` works well in cases like
this.

HTH,
Wayne
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to