[Tutor] anecdote in the workplace about try,except clause
Simon Brunning
SBrunning@trisystems.co.uk
Fri, 17 Aug 2001 09:16:00 +0100
> From: Remco Gerlich [SMTP:scarblac@pino.selwerd.nl]
> > for line in file:
> > try:
> > data, garbage = string.split(line, ':')
> > except ValueError:
> > pass
> >
> > print 'Data: %s' % data
> >
> > What he failed to realize is that when the except clause is triggered
> items in
> > the try clause go out of scope. So data would not exist.
>
> try: doesn't have it's own scope, so data doesn't go out of scope. But it
> was never assigned to in that loop.
>
> I'd expect the print to print the data from the previous run through the
> loop.
Unless it failed first time through, in which case he would get a NameError.
Perhaps this is what makes Sean think that data is going 'out of scope'?
Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning@trisystems.co.uk
-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.