On Sun, 2014-02-09 at 13:36 +0000, Oscar Benjamin wrote: […] > I agree entirely, but what you've overlooked is that my examples are > carefully targeted at a particular part of a tutorial-based class. > We're talking about iteration so this is quite early in the course. At > this stage I want my students to understand that closing a file is an > explicit action that needs to occur. Later in the course I will teach > exception handling and explain that the above should be rewritten as > > f = open('myfile.txt') > try: > for line in f: > print(line.upper()) > finally: > f.close() > > Shortly after that we will look at using (but not creating) context > managers and I'll explain that file objects are also context managers.
Works for me. Personally I would ensure I put in forward signposts at the time of covering earlier codes to ensure people realize there is a progression and that the current code is initial not final. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor