2017-06-12 11:31 GMT+02:00 Raffaele Salmaso <raffa...@salmaso.org>: > 2017-06-12 11:21 GMT+02:00 Daniele Zambelli <daniele.zambe...@gmail.com>: >> >> Il 9 giugno 2017 12:09, Davide Olianas <dav...@davideolianas.com> ha >> scritto: >> > with open('pippo', 'rb') as f: >> > oggetto = pickle.load(f) >> Perché usare with e non semplicemente: >> f = open('pippo', 'rb') >> oggetto = pickle.load(f) >> ? > > Così ti rimane aperto il file inutilmente, col with invece lo chiudi appena > hai finito di usarlo. > Per uno script usa e getta potrebbe non essere un problema, ma in generale > meglio liberare le risorse usate appena possibile.
Inoltre se non chiudi esplicitamente il file, Windows™ non lo scrive su disco, abbiamo scoperto. ㎝ -- |:**THE 🍺-WARE LICENSE** *(Revision ㊷)*: | <miron@🐍.it> wrote this mail. As long as you retain this | notice you can do whatever you want with this stuff. | If we meet some day, and you think this stuff is worth it, | you can buy me a 🍺 in return. —㎝ _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python