[Tutor] Splitting a string

David Hutto smokefloat at gmail.com
Tue Feb 8 14:38:50 CET 2011


On Tue, Feb 8, 2011 at 8:36 AM, Christian Witts <cwitts at compuscan.co.za> wrote:
> On 08/02/2011 15:04, tee chwee liong wrote:
>>
>> hi all,
>>
>> thanks for the advice. i modified my code to be:
>>
>> c=('01101')
>> i=-1
>> try:
>>    while 1:
>>        i=c.index('0',i+1)
>>        print "Lane fail",i
>> except ValueError:
>>    print "All Lanes PASS"
>>    pass
>>
>> when i run, the result is:
>>
>> >>>
>> Lane fail 0
>> Lane fail 3
>> All Lanes PASS
>>
>> Question: How do i prevent the code from executing the except ValueError
>> part. it seems to be checking bit by bit and when is see 1 it will execute
>> the except part.
>> i just want the results to be:
>> >>>
>> Lane fail 0
>> Lane fail 3
>>
>>
>> thanks
>> tcl76
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
> `while i < len(c)` instead of `while 1`

You remind me of me...like it was yesterday. Explanations with no
thought. Unimpressive isn't it?

>
> --
> Kind Regards,
> Christian Witts
>
>
>



-- 
According to theoretical physics, the division of spatial intervals as
the universe evolves gives rise to the fact that in another timeline,
your interdimensional counterpart received helpful advice from me...so
be eternally pleased for them.


More information about the Tutor mailing list