<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div id="yiv5876191942" class="" style=""><div class="" style=""><div style="background-color: rgb(255, 255, 255); font-size: 10pt" class=""><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="color: rgb(0, 0, 0); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif"><span class="" id="yiv5876191942yui_3_13_0_7_1399448226428_26" style="">Intanto grazie per la risposta,</span></div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="color: rgb(0, 0, 0); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13.333333969116211px; background-color: transparent; font-style: normal"><span class="" id="yiv5876191942yui_3_13_0_7_1399448226428_20" style=""><br clear="none"
 style="font-family:monospace"><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>> if __name__ == '__main__':</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>>    try:</span><br clear="none" class="" style="font-family:monospace"><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_10255" style="font-family:monospace">>>        csv_rapportino=ftp_connection.ftp_importazione()</span><br clear="none" class="" style="font-family:monospace"><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_10256" style="font-family:monospace">>>        db=SQLServer_connection.DB_connection().connect()</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>> </span><br clear="none" class=""
 style="font-family:monospace"><span class="" style="font-family:monospace">>>    ...</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>></span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>>    except:</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>>        sys.exit()</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>> </span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>>    finally:</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>>        csv_rapportino.__exit__()</span><br clear="none"
 class="" style="font-family:monospace"><span class="" style="font-family:monospace">>>        db.__exit__()</span><br clear="none" class="" style="font-family:monospace"><br clear="none" class="" style="font-family:monospace"><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_10249" style="font-family:monospace">>Dal (poco) codice che hai postato sembra che i due oggetti</span><br clear="none" class="" style="font-family:monospace"><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_9495" style="font-family:monospace">>ftp_connection e SQLServer_connection vadano usati cosí:</span><br clear="none" class="" style="font-family:monospace"><br clear="none" class="" style="font-family:monospace"><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>if __name__ == '__main__':</span><br clear="none" class="" style="font-family:monospace"><span class=""
 id="yiv5876191942yui_3_13_0_1_1399448226428_9485" style="font-family:monospace">>    with (ftp_connection.ftp_importazione() as csv_rapportino,</span><br clear="none" class="" style="font-family:monospace"><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_9486" style="font-family:monospace">>          SQLServer_connection.DB_connection().connect() as db):</span><br clear="none" class="" style="font-family:monospace">><br clear="none" class="" style="font-family:monospace"><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_9487" style="font-family:monospace">>    # resto del codice nel "try:" originale qui</span><br clear="none" class="" style="font-family:monospace"><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>Questo perché:</span><br clear="none" class="" style="font-family:monospace">><br clear="none" class=""
 style="font-family:monospace"><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_9493" style="font-family:monospace">>- lo statement "with" si occupa di chiamare __exit__() all'uscita dal</span><br clear="none" class="" style="font-family:monospace"><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_9494" style="font-family:monospace">>blocco, indipendentemente dal fatto che si sia verificata un'eccezione</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>nel mezzo o meno</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>(</span><a rel="nofollow" shape="rect" class="" id="yiv5876191942yui_3_13_0_1_1399448226428_8304" target="_blank" href="https://docs.python.org/2/reference/compound_stmts.html#the-with-statement" style="background-color:rgb(255, 255, 255);color:rgb(25, 106,
 212);font-family:monospace">https://docs.python.org/2/reference/compound_stmts.html#the-with-statement</a><span class="" style="font-family:monospace">)</span><br clear="none" class="" style="font-family:monospace"><br clear="none" class="" style="font-family:monospace"><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_10257" style="font-family:monospace">>- sempre "with" si occupa anche di chiamare __enter__() all'entrata del</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>blocco (non conosoco le classi che stai usando, ma é anche possibile che</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>la connessione venga effettuata lí..)</span><br clear="none" class="" style="font-family:monospace"><br class="" style="">Esatto :) infatti ho letto varie volte come usare lo statement With, ma non mi è ancora entrato in
 testa... quindi per cominciare se non altro ad abituarmi utilizzo comunque __enter__ ed __exit__ nelle mie classi. Diciamo che l'obiettivo è quello di usarlo :_)<br class="" style=""><br class="" style=""><br clear="none" class="" style="font-family:monospace"><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_10258" style="font-family:monospace">>- non nascondere le eccezioni quando non serve: quell'``except:</span><br clear="none" class="" style="font-family:monospace"><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_10259" style="font-family:monospace">>sys.exit()`` é completamente inutile (in caso di eccezione non gestita,</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>l'interprete sa che deve terminare l'esecuzione con codice di errore)</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>peró maschera
 un traceback potenzialmente utile per capire cosa é andato</span><br clear="none" class="" style="font-family:monospace"><span class="" style="font-family:monospace">>storto..</span><br clear="none" class="" style="font-family:monospace"><br clear="none" class="" style="font-family:monospace">Non è mai un bene nasconderle, avevo fatto ciò perché se non facevo uscire il programma in caso di eccezione python e pyscripter mi si piantavano, quindi è una cosa temporanea.</span></div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="color: rgb(0, 0, 0); font-size: 13.333333969116211px; background-color: transparent; font-style: normal"><span class="" style=""><font face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif" class="" style=""><br class="" style=""></font></span></div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="color: rgb(0, 0, 0); font-size: 13.333333969116211px;
 background-color: transparent; font-style: normal"><span class="" style=""><font face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif" class="" style="">Infine ho trovato l'errore:</font></span></div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="font-size: 13.333333969116211px; background-color: transparent; font-style: normal"><span class="" style=""><span class="" style="color: rgb(0, 0, 0)">>> if __name__ == '__main__':</span><br clear="none" class="" style=""><span class="" style="color: rgb(0, 0, 0)">>>    try:</span><br clear="none" class="" style=""><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_10255" style="color: rgb(0, 0, 0)">>>        csv_rapportino=ftp_connection.ftp_importazione()</span><br clear="none" class="" style=""><span class="" id="yiv5876191942yui_3_13_0_1_1399448226428_10256" style="">>>       #<span
 style="color: rgb(205, 35, 44)" class="">db=SQLServer_connection.DB_connection().connect()</span></span></span></div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="font-size: 13.333333969116211px; background-color: transparent; font-style: normal"><span style="color: rgb(91, 136, 40)" class=""><span class="" style=""><span class="" style=""><span class="" style="">              db=</span></span></span><span style="font-size: 10pt" class="">SQLServer_connection.DB_connection()</span></span></div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="font-size: 13.333333969116211px; background-color: transparent; font-style: normal"><span style="font-size: 10pt; color: rgb(91, 136, 40)" class="">              db.connect()</span></div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="font-size: 13.333333969116211px; background-color:
 transparent; font-style: normal"><span class="" style=""><span style="color: rgb(205, 35, 44)" class=""><br clear="none" class="" style=""></span><span class="" style="color: rgb(0, 0, 0)">>> </span><br clear="none" class="" style=""><span class="" style="color: rgb(0, 0, 0)">>>    ...</span><br clear="none" class="" style=""><span class="" style="color: rgb(0, 0, 0)">>></span><br clear="none" class="" style=""><span class="" style="color: rgb(0, 0, 0)">>>    except:</span><br clear="none" class="" style=""><span class="" style="color: rgb(0, 0, 0)">>>        sys.exit()</span><br clear="none" class="" style=""><span class="" style="color: rgb(0, 0, 0)">>> </span><br clear="none" class="" style=""><span class="" style="color: rgb(0, 0, 0)">>>    finally:</span><br clear="none" class="" style=""><span class="" style="color: rgb(0, 0, 0)">>> 
       csv_rapportino.__exit__()</span><br clear="none" class="" style=""><span class="" style="color: rgb(0, 0, 0)">>>        db.__exit__()</span><font face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif" class="" style="color: rgb(0, 0, 0)"><font face="HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif" class="" style=""><br class="" style=""></font></font></span></div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="color: rgb(0, 0, 0); font-size: 13.333333969116211px; background-color: transparent; font-style: normal"><br class="" style=""></div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="color: rgb(0, 0, 0); font-size: 13.333333969116211px; background-color: transparent; font-style: normal">In pratica quando cercavo di chiudere l'oggetto, richiamando db.__exit__() pensavo di richiamare il metodo della mia classe,
 mentre avendo prima sbagliato l'assegnazione andavo a richiamare il metodo __exit__ di un oggetto tipo pyodbc.Connection, con gli effetti nefasti che ho postato...</div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="color: rgb(0, 0, 0); font-size: 13.333333969116211px; background-color: transparent; font-style: normal">E' stata dura, ma l'ho scovato.</div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="color: rgb(0, 0, 0); font-size: 13.333333969116211px; background-color: transparent; font-style: normal">Grazie mille dei suggerimenti e vedrò di far pratica con il With.</div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="color: rgb(0, 0, 0); font-size: 13.333333969116211px; background-color: transparent; font-style: normal"><br></div><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_13" style="color: rgb(0, 0, 0); font-size: 13.333333969116211px; background-color: transparent;
 font-style: normal">Piergiorgio</div><div class="" id="yiv5876191942yqt14326" style="color: rgb(0, 0, 0); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif"><div class="" id="yiv5876191942yui_3_13_0_7_1399448226428_15" style="display: none"> <div class="" style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"> <div class="" style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"> <div class="" dir="ltr" style=""> <font class="" size="2" face="Arial" style=""> Il Mercoledì 7 Maggio 2014 12:00, "python-request@lists.python.it" <python-request@lists.python.it> ha scritto:<br clear="none" class="" style=""> </font> </div>  <div class="" style="">Invia le richieste di iscrizione alla lista
 Python all'indirizzo<br clear="none" class="" style="">    <a rel="nofollow" shape="rect" class="" ymailto="mailto:python@lists.python.it" target="_blank" href="mailto:python@lists.python.it" style="">python@lists.python.it</a><br clear="none" class="" style=""><br clear="none" class="" style="">Per iscriverti o cancellarti attraverso il web, visita<br clear="none" class="" style="">    <a rel="nofollow" shape="rect" class="" target="_blank" href="http://lists.python.it/mailman/listinfo/python" style="">http://lists.python.it/mailman/listinfo/python</a><br clear="none" class="" style="">oppure, via email, manda un messaggio con oggetto `help' all'indirizzo<br clear="none" class="" style="">    <a rel="nofollow" shape="rect" class="" ymailto="mailto:python-request@lists.python.it" target="_blank" href="mailto:python-request@lists.python.it" style="">python-request@lists.python.it</a><br clear="none" class=""
 style=""><br clear="none" class="" style="">Puoi contattare la persona che gestisce la lista all'indirizzo<br clear="none" class="" style="">    <a rel="nofollow" shape="rect" class="" ymailto="mailto:python-owner@lists.python.it" target="_blank" href="mailto:python-owner@lists.python.it" style="">python-owner@lists.python.it</a><br clear="none" class="" style=""><br clear="none" class="" style="">Se rispondi a questo messaggio, per favore edita la linea dell'oggetto<br clear="none" class="" style="">in modo che sia più utile di un semplice "Re: Contenuti del digest<br clear="none" class="" style="">della lista Python..."<br clear="none" class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style="">Argomenti del Giorno:<br clear="none" class="" style=""><br clear="none" class="" style="">   1. Re: Interessante anche se datato (Carlo Miron)<br clear="none" class="" style="">   2. Re: Interessante anche
 se datato (Marco Beri)<br clear="none" class="" style="">   3. Re: Utile sito, sopratutto per i newbies (Carlos Catucci)<br clear="none" class="" style="">   4. Re: Strana eccezione (~redShadow~)<br clear="none" class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style="">----------------------------------------------------------------------<br clear="none" class="" style=""><br clear="none" class="" style="">Message: 1<br clear="none" class="" style="">Date: Tue, 6 May 2014 12:18:18 +0200<br clear="none" class="" style="">From: Carlo Miron <<a rel="nofollow" shape="rect" class="" ymailto="mailto:miron@python.it" target="_blank" href="mailto:miron@python.it" style="">miron@python.it</a>><br clear="none" class="" style="">To: Discussioni generali sul linguaggio Python<br clear="none" class="" style="">    <<a rel="nofollow" shape="rect" class="" ymailto="mailto:python@lists.python.it"
 target="_blank" href="mailto:python@lists.python.it" style="">python@lists.python.it</a>><br clear="none" class="" style="">Subject: Re: [Python] Interessante anche se datato<br clear="none" class="" style="">Message-ID:<br clear="none" class="" style="">    <<a rel="nofollow" shape="rect" class="" ymailto="mailto:CAFp98etMyLdCiujKps1RaaQ0ne-BPn59V4ucJo1pueY4ni6PXg@mail.gmail.com" target="_blank" href="mailto:CAFp98etMyLdCiujKps1RaaQ0ne-BPn59V4ucJo1pueY4ni6PXg@mail.gmail.com" style="">CAFp98etMyLdCiujKps1RaaQ0ne-BPn59V4ucJo1pueY4ni6PXg@mail.gmail.com</a>><br clear="none" class="" style="">Content-Type: text/plain; charset=UTF-8<br clear="none" class="" style=""><br clear="none" class="" style="">Il 05 maggio
 2014 15:11, Marco Beri ha scritto::<br clear="none" class="" style=""><br clear="none" class="" style="">> 2014-05-05 12:30 GMT+02:00 Daniele Varrazzo <<a rel="nofollow" shape="rect" class="" ymailto="mailto:piro@develer.com" target="_blank" href="mailto:piro@develer.com" style="">piro@develer.com</a>>:<br clear="none" class="" style="">><br clear="none" class="" style="">>> Perchè sei un vegliardo: tutto quello per cui i db relazionali sono stati<br clear="none" class="" style="">>> inventati oggi non vale più e si può fare a meno delle loro proprietà.<br clear="none" class="" style="">>> Totalmente.<br clear="none" class="" style="">>> <a rel="nofollow" shape="rect" class="" target="_blank" href="http://hackingdistributed.com/2014/04/06/another-one-bites-the-dust-flexcoin/" style="">http://hackingdistributed.com/2014/04/06/another-one-bites-the-dust-flexcoin/</a><br clear="none" class="" style="">><br
 clear="none" class="" style="">> Ma cavolo, l'ho dovuto rileggere due volte prima di capire che mi prendevi<br clear="none" class="" style="">> in giro... due volte: per il vegliardo e perché alla fine
 concordi che i<br clear="none" class="" style="">> relazionali in alcuni casi sono ancora insostituibili (il concetto di<br clear="none" class="" style="">> transazione, per lo meno, lo è ancora).<br clear="none" class="" style=""><br clear="none" class="" style="">Marco, qualora il tuo alzheimer sia cosi` galoppante da averti fatto<br clear="none" class="" style="">dimenticare chi sia il tuo interlocutore, ti presento piro...<br clear="none" class="" style=""><br clear="none" class="" style="">©<br clear="none" class="" style=""><br clear="none" class="" style="">-- <br clear="none" class="" style=""> :**THE BEER-WARE LICENSE** (Revision 42):<br clear="none" class="" style="">   ``miron AT python.it`` wrote this mail. As long as you retain this notice<br clear="none" class="" style="">   you can do whatever you want with this stuff. If we meet some day, and you<br clear="none" class="" style="">   think this stuff is worth it,
 you can buy me a beer in return.<br clear="none" class="" style=""><br clear="none" class="" style="">   --*Carlo Miron*<br clear="none" class="" style=""><br clear="none" class="" style="">  ..<br clear="none" class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style="">------------------------------<br clear="none" class="" style=""><br clear="none" class="" style="">Message: 2<br clear="none" class="" style="">Date: Tue, 6 May 2014 12:21:05 +0200<br clear="none" class="" style="">From: Marco Beri <<a rel="nofollow" shape="rect" class="" ymailto="mailto:marcoberi@gmail.com" target="_blank" href="mailto:marcoberi@gmail.com" style="">marcoberi@gmail.com</a>><br clear="none" class="" style="">To: Discussioni generali sul linguaggio Python<br clear="none" class="" style="">    <<a rel="nofollow" shape="rect" class="" ymailto="mailto:python@lists.python.it" target="_blank"
 href="mailto:python@lists.python.it" style="">python@lists.python.it</a>><br clear="none" class="" style="">Subject: Re: [Python] Interessante anche se datato<br clear="none" class="" style="">Message-ID:<br clear="none" class="" style="">    <CAN1J36idHNNT7NyxaiE47GG=<a rel="nofollow" shape="rect" class="" ymailto="mailto:DpbyEsy-7QXjk-5vPtFgRruGtg@mail.gmail.com" target="_blank" href="mailto:DpbyEsy-7QXjk-5vPtFgRruGtg@mail.gmail.com" style="">DpbyEsy-7QXjk-5vPtFgRruGtg@mail.gmail.com</a>><br clear="none" class="" style="">Content-Type: text/plain; charset="utf-8"<br clear="none" class="" style=""><br clear="none" class="" style="">2014-05-06 12:18 GMT+02:00 Carlo Miron <<a rel="nofollow" shape="rect" class="" ymailto="mailto:miron@python.it" target="_blank" href="mailto:miron@python.it" style="">miron@python.it</a>>:<br clear="none" class="" style=""><br clear="none" class="" style="">> Il 05 maggio 2014 15:11, Marco
 Beri ha scritto::<br clear="none" class="" style="">><br clear="none" class="" style="">> > 2014-05-05 12:30 GMT+02:00 Daniele Varrazzo <<a rel="nofollow" shape="rect" class="" ymailto="mailto:piro@develer.com" target="_blank" href="mailto:piro@develer.com" style="">piro@develer.com</a>>:<br clear="none" class="" style="">> ><br clear="none" class="" style="">> >> Perchè sei un vegliardo: tutto quello per cui i db relazionali sono<br clear="none" class="" style="">> stati<br clear="none" class="" style="">> >> inventati oggi non vale più e si può fare a meno delle loro proprietà.<br clear="none" class="" style="">> >> Totalmente.<br clear="none" class="" style="">> >><br clear="none" class="" style="">> <a rel="nofollow" shape="rect" class="" target="_blank" href="http://hackingdistributed.com/2014/04/06/another-one-bites-the-dust-flexcoin/"
 style="">http://hackingdistributed.com/2014/04/06/another-one-bites-the-dust-flexcoin/</a><br clear="none" class="" style="">> ><br clear="none" class="" style="">> > Ma cavolo, l'ho dovuto rileggere due volte prima di capire che mi<br clear="none" class="" style="">> prendevi<br clear="none" class="" style="">> > in giro... due volte: per il vegliardo e perché alla fine concordi che i<br clear="none" class="" style="">> > relazionali in alcuni casi sono ancora insostituibili (il concetto di<br clear="none" class="" style="">> > transazione, per lo meno, lo è ancora).<br clear="none" class="" style="">><br clear="none" class="" style="">> Marco, qualora il tuo alzheimer sia cosi` galoppante da averti fatto<br clear="none" class="" style="">> dimenticare chi sia il tuo interlocutore, ti presento piro...<br clear="none" class="" style="">><br clear="none" class="" style=""><br clear="none" class=""
 style="">È vero, ma "piro" lo sappiamo tutti che deriva
 da "pirotecnico".<br clear="none" class="" style=""><br clear="none" class="" style="">Pensavo fosse una delle sue solite magie... ;-)<br clear="none" class="" style=""><br clear="none" class="" style="">Ciao.<br clear="none" class="" style="">Marco.<br clear="none" class="" style="">P.S. In realtà mica lo ricordo da cosa deriva "piro" anche se una volta me<br clear="none" class="" style="">l'aveva detto mi pare.<br clear="none" class="" style=""><br clear="none" class="" style="">-- <br clear="none" class="" style=""><a rel="nofollow" shape="rect" class="" target="_blank" href="http://beri.it/" style="">http://beri.it/ </a>- Un blog<br clear="none" class="" style=""><a rel="nofollow" shape="rect" class="" target="_blank" href="http://beri.it/i-miei-libri/" style="">http://beri.it/i-miei-libri/ </a>- Qualche libro<br clear="none" class="" style="">-------------- parte successiva --------------<br clear="none" class="" style="">Un allegato HTML è stato
 rimosso...<br clear="none" class="" style="">URL: <<a rel="nofollow" shape="rect" class="" target="_blank" href="http://lists.python.it/pipermail/python/attachments/20140506/51d97be0/attachment-0001.html" style="">http://lists.python.it/pipermail/python/attachments/20140506/51d97be0/attachment-0001.html</a>><br clear="none" class="" style=""><br clear="none" class="" style="">------------------------------<br clear="none" class="" style=""><br clear="none" class="" style="">Message: 3<br clear="none" class="" style="">Date: Tue, 6 May 2014 14:01:59 +0200<br clear="none" class="" style="">From: Carlos Catucci <<a rel="nofollow" shape="rect" class="" ymailto="mailto:carlos.catucci@gmail.com" target="_blank" href="mailto:carlos.catucci@gmail.com" style="">carlos.catucci@gmail.com</a>><br clear="none" class="" style="">To: Discussioni generali sul linguaggio Python<br clear="none" class="" style="">    <<a rel="nofollow"
 shape="rect" class="" ymailto="mailto:python@lists.python.it" target="_blank" href="mailto:python@lists.python.it" style="">python@lists.python.it</a>><br clear="none" class="" style="">Subject: Re: [Python] Utile sito, sopratutto per i newbies<br clear="none" class="" style="">Message-ID:<br clear="none" class="" style="">    <<a rel="nofollow" shape="rect" class="" ymailto="mailto:CAEaPG9QnEXVVWaQdCLNejKL17qR3CcwZR1aZ19xO4wqYYKm-kA@mail.gmail.com" target="_blank" href="mailto:CAEaPG9QnEXVVWaQdCLNejKL17qR3CcwZR1aZ19xO4wqYYKm-kA@mail.gmail.com" style="">CAEaPG9QnEXVVWaQdCLNejKL17qR3CcwZR1aZ19xO4wqYYKm-kA@mail.gmail.com</a>><br clear="none" class="" style="">Content-Type: text/plain; charset="utf-8"<br clear="none" class="" style=""><br clear="none" class="" style="">Altro interessante sitarello<br clear="none" class="" style=""><br clear="none" class="" style=""><a rel="nofollow" shape="rect" class="" target="_blank"
 href="http://tutorials.tutsplus.com/" style="">http://tutorials.tutsplus.com/</a><br clear="none" class="" style=""><br clear="none" class="" style="">Carlos<br clear="none" class="" style="">-- <br clear="none" class="" style="">Coloro che sognano di giorno sono uomini pericolosi, perche' sono capaci di<br clear="none" class="" style="">recitare a occhi aperti il loro sogno fino a renderlo possibile. Ed e'<br clear="none" class="" style="">questo che feci anch'io. - (T.E. Lawrence)<br clear="none" class="" style="">-------------- parte successiva --------------<br clear="none" class="" style="">Un allegato HTML è stato rimosso...<br clear="none" class="" style="">URL: <<a rel="nofollow" shape="rect" class="" target="_blank" href="http://lists.python.it/pipermail/python/attachments/20140506/2b3b2add/attachment-0001.html" style="">http://lists.python.it/pipermail/python/attachments/20140506/2b3b2add/attachment-0001.html</a>><br clear="none"
 class="" style=""><br clear="none" class="" style="">------------------------------<br clear="none" class="" style=""><br clear="none" class="" style="">Message: 4<br clear="none" class="" style="">Date: Tue, 06 May 2014 14:16:20 +0200<br clear="none" class="" style="">From: ~redShadow~ <<a rel="nofollow" shape="rect" class="" ymailto="mailto:redshadow@hackzine.org" target="_blank" href="mailto:redshadow@hackzine.org" style="">redshadow@hackzine.org</a>><br clear="none" class="" style="">To: <a rel="nofollow" shape="rect" class="" ymailto="mailto:python@lists.python.it" target="_blank" href="mailto:python@lists.python.it" style="">python@lists.python.it</a><br clear="none" class="" style="">Subject: Re: [Python] Strana eccezione<br clear="none" class="" style="">Message-ID: <<a rel="nofollow" shape="rect" class="" ymailto="mailto:5368D294.1060805@hackzine.org" target="_blank" href="mailto:5368D294.1060805@hackzine.org"
 style="">5368D294.1060805@hackzine.org</a>><br clear="none" class="" style="">Content-Type: text/plain; charset=ISO-8859-1<br clear="none" class="" style=""><br clear="none" class="" style="">On 05/06/2014 10:28 AM, piergiorgio pancino wrote:<br clear="none" class="" style="">> if __name__ == '__main__':<br clear="none" class="" style="">>     try:<br clear="none" class="" style="">>         csv_rapportino=ftp_connection.ftp_importazione()<br clear="none" class="" style="">>         db=SQLServer_connection.DB_connection().connect()<br clear="none" class="" style="">> <br clear="none" class="" style="">>     ...<br clear="none" class="" style="">><br clear="none" class="" style="">>     except:<br clear="none" class="" style="">>         sys.exit()<br clear="none" class="" style="">> <br clear="none" class="" style="">> 
    finally:<br clear="none" class="" style="">>         csv_rapportino.__exit__()<br clear="none" class="" style="">>         db.__exit__()<br clear="none" class="" style=""><br clear="none" class="" style="">Dal (poco) codice che hai postato sembra che i due oggetti<br clear="none" class="" style="">ftp_connection e SQLServer_connection vadano usati cosí:<br clear="none" class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style="">if __name__ == '__main__':<br clear="none" class="" style="">    with (ftp_connection.ftp_importazione() as csv_rapportino,<br clear="none" class="" style="">          SQLServer_connection.DB_connection().connect() as db):<br clear="none" class="" style=""><br clear="none" class="" style="">    # resto del codice nel "try:" originale qui<br clear="none" class="" style=""><br clear="none" class=""
 style=""><br clear="none" class="" style="">Questo perché:<br clear="none" class="" style=""><br clear="none" class="" style="">- lo statement "with" si occupa di chiamare __exit__() all'uscita dal<br clear="none" class="" style="">blocco, indipendentemente dal fatto che si sia verificata un'eccezione<br clear="none" class="" style="">nel mezzo o meno<br clear="none" class="" style="">(<a rel="nofollow" shape="rect" class="" target="_blank" href="https://docs.python.org/2/reference/compound_stmts.html#the-with-statement" style="">https://docs.python.org/2/reference/compound_stmts.html#the-with-statement</a>)<br clear="none" class="" style=""><br clear="none" class="" style="">- sempre "with" si occupa anche di chiamare __enter__() all'entrata del<br clear="none" class="" style="">blocco (non conosoco le classi che stai usando, ma é anche possibile che<br clear="none" class="" style="">la connessione venga effettuata lí..)<br clear="none" class=""
 style=""><br clear="none" class="" style="">- non nascondere le eccezioni quando non serve: quell'``except:<br clear="none" class="" style="">sys.exit()`` é completamente inutile (in caso di eccezione non gestita,<br clear="none" class="" style="">l'interprete sa che deve terminare l'esecuzione con codice di errore)<br clear="none" class="" style="">peró maschera un traceback potenzialmente utile per capire cosa é andato<br clear="none" class="" style="">storto..<br clear="none" class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style="">-- <br clear="none" class="" style="">  Samuele ~redShadow~ Santi<br clear="none" class="" style=""><br clear="none" class="" style="">----------------------------------------------------------------------<br clear="none" class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style="">                  ----( 
 Contact information  )----<br clear="none" class="" style=""><br clear="none" class="" style="">                   E-MAIL:  <a rel="nofollow" shape="rect" class="" ymailto="mailto:redshadow@hackzine.org" target="_blank" href="mailto:redshadow@hackzine.org" style="">redshadow@hackzine.org</a><br clear="none" class="" style="">                     BLOG:  <a rel="nofollow" shape="rect" class="" target="_blank" href="http://www.hackzine.org/" style="">http://www.hackzine.org</a><br clear="none" class="" style="">                     WIKI:  <a rel="nofollow" shape="rect" class="" target="_blank" href="http://wiki.hackzine.org/" style="">http://wiki.hackzine.org</a><br clear="none" class="" style="">                  TWITTER:  <a rel="nofollow"
 shape="rect" class="" target="_blank" href="https://twitter.com/_rshk" style="">https://twitter.com/_rshk</a><br clear="none" class="" style="">                   GITHUB:  <a rel="nofollow" shape="rect" class="" target="_blank" href="https://github.com/rshk" style="">https://github.com/rshk</a><br clear="none" class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style="">                  ----(  GPG Key: 09F09951  )----<br clear="none" class="" style=""><br clear="none" class="" style="">          1AFC FAE5 CA4B 3FB0 F300 FA64 3CB0 1008 09F0 9951<br clear="none" class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style="">             ----(  Registered Linux-User: #440008  )----<br clear="none" class="" style=""><br clear="none"
 class="" style="">     
     DEBIAN User since 2004 (I even used Sid!)<br clear="none" class="" style="">             GENTOO User since 2008-01-01<br clear="none" class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style="">----------------------------------------------------------------------<br clear="none" class="" style=""><br clear="none" class="" style="">  Think about the environment: for each top-posted, badly quoted<br clear="none" class="" style="">  or bulk e-mail I receive, I'm going to cut down a tree.<br clear="none" class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style="">------------------------------<br clear="none" class="" style=""><br clear="none" class="" style="">_______________________________________________<br clear="none" class="" style="">Python mailing list<br clear="none" class="" style=""><a rel="nofollow" shape="rect" class=""
 ymailto="mailto:Python@lists.python.it" target="_blank" href="mailto:Python@lists.python.it" style="">Python@lists.python.it</a><br clear="none" class="" style=""><a rel="nofollow" shape="rect" class="" target="_blank" href="http://lists.python.it/mailman/listinfo/python" style="">http://lists.python.it/mailman/listinfo/python</a><br clear="none" class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style="">Fine di Digest di Python, Volume 99, Numero 10<br clear="none" class="" style="">**********************************************<br clear="none" class="" style=""><br clear="none" class="" style=""></div>  </div> </div>  </div></div> </div></div></div></div></body></html>