2017-06-12 11:31 GMT+02:00 Raffaele Salmaso <[email protected]>:
> 2017-06-12 11:21 GMT+02:00 Daniele Zambelli <[email protected]>:
>>
>> Il 9 giugno 2017 12:09, Davide Olianas <[email protected]> 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
[email protected]
http://lists.python.it/mailman/listinfo/python

Rispondere a