[Tutor] anecdote in the workplace about try,except clause
Sean 'Shaleh' Perry
shalehperry@home.com
Sun, 19 Aug 2001 01:42:55 -0700 (PDT)
On 18-Aug-2001 alan.gauld@bt.com wrote:
> Since we have established that data doesn't go out of scope...
>
>> > > for line in file:
>> > > try:
>> > > data, garbage = string.split(line, ':')
>> > > except ValueError:
> data = line
>
> should fix it, no?
>
> The comment about data going out of scope confused me but
> now that thats been cleared up the simple fix above should
> work (my trivial tests so far suggest it does...)
>
the more proper approach in my opinion would be to test if there is a colon to
be begin with. Which is what I suggested he do. The actual application was a
summer which read a file and sum the statistics on each line. The first N
lines were header and other info.