[Tutor] Program review

Ricardo Aráoz ricaraoz at gmail.com
Tue Jan 8 01:15:44 CET 2008


Kent Johnson wrote:
> Ricardo Aráoz wrote:
>> PEP 0343 is not an
>> example of clarity in the definition of a statement, it mixes
>> justification with historic development with definition with actual
>> equivalent code. Couldn't or wouldn't bother to understand it.
> 
> Here is a better starting point:
> http://docs.python.org/whatsnew/pep-343.html
> 
> Kent
> 

Thanks Kent, it's clearer, but it gets rapidly complicated. Anyway
looking at the simpler use, if you would have exception handling in :

try :
    with open('/etc/passwd', 'r') as f:
        for line in f:
            print line
            ... more processing code ...
except ExceptionsOnOpening :
    ... exception handling
except :
    ... exceptions inside the for



Whereas traditionally :

try :
    f = open('/etc/passwd', 'r')
    for line in f:
        print line
        ... more processing code ...
except ExceptionsOnOpening :
    ... exception handling
except :
    ... exceptions inside the for


I don't see much difference except in the with example you have one more
level of indentation.

Don't know about more advanced uses, I'll try to understand them when
and if I ever need them.








More information about the Tutor mailing list